var testEditor;
$(function() {
    var Alert1 = new Alert();
    var Alert2 = new Alert();
    var Alert3 = new Alert();
    var Alert5 = new Alert();
    var confirm1 = new Confirm();
    var confirm3 = new Confirm();
    var loading1 = new Loading();
    loading1.init();
    var $chapterList = $("#chapterList");
    var $iconfont = $(".iconfont");
    var $showSection = $(".showSection");
    var $mb = $(".mb");
    var $mainContents = $(".mainContents");
    var num =0;
    var count = 0;
    function choseModel(num,opt){

//		选择题模板
        var str1 = "";
        // count = num-1;
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +" class=\"questionBox\">"
                +"<div>"+ num +"."+ this.tasklibraryName +"(&emsp;&emsp;)(<i style='font-style: normal;' class=\"fen\">"+ this.tasklibrarySource +"</i>分)<i style='font-style: normal;' class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</i></div>"
            $.each(this.tasklibraryOptionMsg.split("#"), function(omg) {
                str1 += "<div class=\"choseOne\">"+ this +"</div>"
            });
            str1 +="</div>";
        });

        return str1;
    }
    function muchModel(num,opt,obj){
        var str1 = "";
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +" class=\"questionBox\">"
                +"<div>"+ num +"."+ this.tasklibraryName +"(&emsp;&emsp;)(<i style='font-style: normal;' class=\"fen\">"+ this.tasklibrarySource +"</i>分)<i style='font-style: normal;' class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</i></div>"
            $.each(this.tasklibraryOptionMsg.split("#"), function(omg) {
                str1 += "<div class=\"muchOne\">"+ this +"</div>"
            });
            str1 +="</div>";
        });

        return   str1;
    }
    function fillModel(num,opt,obj){

//		填空题模板
        var str1 = "";
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +"  class=\"questionBox\">"
                +"<div class=\"fillAdd\"><i style='font-style: normal;' class=\"fillSpace\">"+ num +"."+ this.tasklibraryName +"</i>(<i style='font-style: normal;' class=\"fen\">"+ this.tasklibrarySource +"</i>分)<div class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</div></div>"
                +"</div>";
        });

        return  str1;
    }
    function checkModel(num,opt,obj){

        var str1 = "";
        var count = 0;
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +"   class=\"questionBox\">"
                +"<div>"+ num +"."+ this.tasklibraryName +"(&emsp;&emsp;)(<i class=\"fen\">"+ this.tasklibrarySource +"</i>分)<i style='font-style: normal;' class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</i></div>"
                +"</div>";
        });
        return str1;

    }
    function shortModel(num,opt,obj){

        var str1 = "";
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +" class=\"questionBox\">"
                +"<div>"+ num +"."+ this.tasklibraryName +"(<i style='font-style: normal;' class=\"fen\">"+ this.tasklibrarySource +"</i>分)<div class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</div></div>"
                +"<div class=\"choseOne\"><textarea maxlength='2000' class=\"shortAnswer answerInt\"></textarea></div>"
                +"</div>";
        });
        return  str1;

    }
    function labModel(opt) {
        return "<b>一、"+ opt.exprelibraryName +"</b><div><br></div><div><b><br></b></div><div><b>二、"+ opt.exprelibraryObjective +"</b></div><div><br></div><div><b><br></b></div><div><b>三、"+ opt.exprelibraryContent +"</b></div><div><br></div><div><b><br></b></div><div><b>四、"+ opt.exprelibraryStep +"</b></div><div><br></div><div><b><br></b></div><div><b>五、"+ opt.exprelibraryResult +"</b></div><div><br></div><div><b><br></b></div><div><b>六、"+ opt.exprelibraryThinkproblem +"</b></div><div><br></div><div><b><br></b></div>";
    }
    function chapterListModel(opt,url){
        var taskAddress = opt.taskAddress;
        if(taskAddress == ""){
            taskAddress = 1;
        }
        var taskFraction =opt.taskFraction;
        if(taskFraction == undefined||taskFraction == null){
            taskFraction = "暂无";
        }
        var submitContent = opt.submitContent;
        if(submitContent == undefined||submitContent == null){
            submitContent = "暂无";
        }
        num++;
        var str = "";
        var str1 = "";
        var str2 = "";
        var str3 = "";
        if(opt.addTestMark == 2){
            str = "<li data-chapterid="+ opt.chapterId +"  >"
                +"<a data-value=\"0\" class=\"oneChapter\"  data-chapterid="+ opt.chapterId +"   data-chapternum="+ opt.chapterNum +" href=\"javascript:;\">"
                +"<div class='chapterNameBox'><span class=\"down\">"+ opt.chapterNum +"-"+ opt.chapterName +"</span><b data-name='"+ opt.chapterName +"' data-num='"+ opt.chapterNum +"'  data-courseid="+ opt.courseId +"  class='editChapterName' data-addtestmark="+ opt.addTestMark +" data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b></div>"
                +"</a>"
                +"<ul class='chapterDetailList'>";
        }else{
            str = "<li data-chapterid="+ opt.chapterId +"  >"
                +"<a data-value=\"0\" class=\"oneChapter\"  data-chapterid="+ opt.chapterId +"   data-chapternum="+ opt.chapterNum +" href=\"javascript:;\">"
                +"<div class='chapterNameBox'><span class=\"down\">"+ opt.chapterNum +"-"+ opt.chapterName +"&ensp;<img class='hadLab' src=\"pc/images/ico_hadLab.png\"></span><b data-name='"+ opt.chapterName +"' data-num='"+ opt.chapterNum +"'  data-courseid="+ opt.courseId +"  class='editChapterName' data-addtestmark="+ opt.addTestMark +" data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b></div>"
                +"</a>"
                +"<ul class='chapterDetailList'>";
        }
        str1 = "<li>"
            +"<a href=\"javascript:;\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.coursewareNameHtml +"' data-value=\"1\" class=\"courseware choseBtn\">学习课件"
            +"</a>"
            +"<b   data-src='"+ url+ opt.coursewareName +"'  data-chapternum='"+ opt.chapterNum +"' class='editChapter' data-type='1' data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b>"
            +"</li>";
        str1 += "<li>"
            +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.courseMaterialName +"'  class=\"courseMaterial choseBtn\">备课材料</a>"
            +"<b  data-src='"+ url+ opt.courseMaterialNameHtml +"'  data-chapternum='"+ opt.chapterNum +"' class='editChapter'  data-type='2' data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b>"
            +"</li>";
        str1 +=	"<li>"
            +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.homeworkNameHtml +"'   class=\"homework choseBtn\">课后作业"
            +"</a>"
            +"<b   data-src='"+ url+ opt.homeworkModelName +"'  data-chapternum='"+ opt.chapterNum +"'  class='editChapter'  data-type='3' data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b>"
            +"</li>";
        // str1 += "<li>"
        //     +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.courseAnswerNameHtml +"'   class=\"courseAnswer\">作业答案"
        //     +"</a>"
        //     +"</li>";
        str2 = "<li>"
            +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.testDocName +"'   class=\"testDoc choseBtn\">实验手册</a>"
            +"<b  data-src='"+ url+ opt.testNameHtml +"'  data-chapternum='"+ opt.chapterNum +"' class='editChapter'  data-type='4' data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b>"
            +"</li>"
            +"<li>"
            +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.videoName +"'  class=\"video choseBtn\">学习视频</a>"
            +"<b  data-src='"+ url+ opt.videoName +"' data-chapternum='"+ opt.chapterNum +"'  class='editChapter'  data-type='5' data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b>"
            +"</li>"
            +"<li>"
            +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.expreNameHtml +"'  class=\"report choseBtn\">实验报告</a>"
            +"<b  data-src='"+ url+ opt.expreNameHtml +"'  class='editChapter'  data-type='7' data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b>"
            +"</li>";
        // if(opt.packageFile != "" && opt.packageFile != undefined && opt.packageFile != null){
        str3 = "<li>"
            +"<a href=\"javascript:;\" data-src='"+url+ opt.packageFile +"' data-value=\"1\"  data-chapterid="+ opt.chapterId +"  class=\"packageFile choseBtn\">课程材料</a>"
            +"<b  data-chapternum='"+ opt.chapterNum +"'  class='editChapter'  data-type='6' data-chapterid="+ opt.chapterId +" ><img src='pc/images/ico_courseEditBtn.png' alt=''>&ensp;编辑</b>"
            +"</li>"
            +"</ul>"
            +"</li>";
        // }else{
        //     str3 = "</ul>"
        //         +"</li>";
        // }

//			理论
        if(opt.addTestMark == 2){
            return str + str1 + str3;
        }
//			实验
        if(opt.addTestMark == 1){
            return str + str2 + str3;
        }
//			理论加实验
        if(opt.addTestMark == 3){
            return str + str1 + str2 + str3;
        }

    }
    function courseWareModel(opt,url,chapterId) {
        var str = '<div class="editSection">' +
            '<div class="fl">' +
            '<label for="courseware">上传学习课件</label>' +
            '<strong class="downHtml" href="'+ url +'">下载学习课件</strong>' +
            '<form enctype="multipart/form-data">' +
            '<input type="file" data-size="50" data-url="addChapterCourseWare" name="courseware" id="courseware" class="file" style="display: none;">' +
            '<input type="text" data-size="50" data-url="addChapterCourseWare" name="chapterId" value="'+ chapterId +'"  style="display: none;">' +
            '</form>';
        if(opt.coursewareName != ''&& opt.coursewareName != undefined&&opt.coursewareName != null){
            str+= '<h5><span>'+opt.coursewareName+'</span><img src="pc/images/ico_uploadRemove.png" data-text="delCourseware" class="delBtn"><i class="tip"><span>提示：</span>仅支持PPTX格式文件上传</i></h5>';
        }else{
            str+= '<h5><i class="tip"><span>提示：</span>仅支持PPTX格式文件上传</i></h5>';
        }
        str+='</div>' +
            '</div>';
        return str;
    }
    function courseMaterialModel(opt,url,chapterId) {
        var str = '<div class="editSection">' +
            '<div class="fl" style="margin: 0">' +
            '<div id="layouts">' +
            '<header>' +
            '<h4 data-chapterid="'+ chapterId +'" class="fl saveMar">保存</h4>' +
            '</header>' +
            '<div id="MarEditormd">' +
            '<textarea style="display:none;">'+ opt +'</textarea>' +
            '</div>' +
            '</div>' +
            '</div>' +
            '</div>';
        return str;
    }
    function testDocModel(opt,url,chapterId) {
        var str = '<div class="editSection">' +
            '<div class="fl" style="margin: 0">' +
            '<div id="layouts">' +
            '<header>' +
            '<h4 data-chapterid="'+ chapterId +'" class="fl saveMar">保存</h4>' +
            '<h4 class="fr enterLab">实验环境</h4>'+
            '</header>' +
            '<div id="MarEditormd">' +
            '<textarea style="display:none;">'+ opt +'</textarea>' +
            '</div>' +
            '</div>' +
            '</div>' +
            '</div>';
        return str;
    }
    function homeworkModel(opt,url,chapterId) {
        var str = '<div class="editSection">' +
            '<div class="fl">' +
            '<label for="homeworkexcel">上传课后作业</label>' +
            '<strong class="downHtml" href="'+ url+'">下载课后作业</strong>' +
            '<form enctype="multipart/form-data">' +
            '<input type="file" data-size="50" data-url="addChapterHomework" name="homeworkexcel" id="homeworkexcel" class="file" style="display: none;">' +
            '<input type="text" data-size="50" data-url="addChapterCourseWare" name="chapterId" value="'+ chapterId +'"  style="display: none;">' +
            '</form>';
        if(opt.homeworkModelName != ''&& opt.homeworkModelName != undefined&&opt.homeworkModelName != null){
            str+= '<h5><span>'+opt.homeworkModelName+'</span><img src="pc/images/ico_uploadRemove.png" data-text="delHomework" class="delBtn"><i class="tip"><span>提示：</span>仅支持EXCEL格式文件上传</i></h5>';
        }else{
            str+= '<h5><i class="tip"><span>提示：</span>仅支持EXCEL格式文件上传</i></h5>';
        }
        str+='</div>' +
            '</div>';
        return str;
    }
    function videoModel(opt,url,chapterId) {
        var str = '<div class="editSection">' +
            '<div class="fl">' +
            '<label for="video">上传学习视频</label>' +
            '<strong class="downHtml" href="'+ url +'" >下载学习视频</strong>' +
            '<form enctype="multipart/form-data">' +
            '<input type="file" data-url="addChapterVideo" name="video" id="video" class="file" style="display: none;">' +
            '<input type="text" data-url="addChapterCourseWare" name="chapterId" value="'+ chapterId +'"  style="display: none;">' +
            '</form>';
        if(opt.videoName != ''&& opt.videoName != undefined&&opt.videoName != null){
            str+= '<h5><span>'+opt.videoName+'</span><img src="pc/images/ico_uploadRemove.png" data-text="delVideo" class="delBtn"><i class="tip"><span>提示：</span>仅支持MP4格式文件上传</i></h5>';
        }else{
            str+= '<h5><i class="tip"><span>提示：</span>仅支持MP4格式文件上传</i></h5>';
        }
        str+='</div>' +
            '</div>';
        return str;
    }
    function packageFileModel(opt,url,chapterId) {
        var str = '<div class="editSection">' +
            '<div class="fl">' +
            '<label for="packageFile">上传课程材料</label>' +
            '<strong class="downHtml" href="'+ url+'">下载课程材料</strong>' +
            '<form enctype="multipart/form-data">' +
            '<input type="file" data-size="50" data-url="addChapterPackageFile" name="packageFile" id="packageFile" class="file" style="display: none;">' +
            '<input type="text" data-size="50" data-url="addChapterCourseWare" name="chapterId" value="'+ chapterId +'"  style="display: none;">' +
            '</form>';
        if(opt.packageFile != ''&& opt.packageFile != undefined&&opt.packageFile != null&&opt.packageFile != 'null'){
            str+= '<h5><span>'+opt.packageFile+'</span><img src="pc/images/ico_uploadRemove.png" data-text="delPackageFile" class="delBtn"><i class="tip"><span>提示：</span>仅支持ZIP,RAR格式文件上传</i></h5>';
        }else{
            str+= '<h5><i class="tip"><span>提示：</span>仅支持ZIP,RAR格式文件上传</i></h5>';
        }
        str+='</div>' +
            '</div>';
        return str;
    }
    function reportModel(opt,url,chapterId) {
        var str = '<div class="editSection">' +
            '<div class="fl" style="margin: 0">' +
            '<div id="layoutr">' +
            '<header>' +
            '<h4 data-chapterid="'+ chapterId +'" class="fl saveReport">保存</h4>' +
            '</header>' +
            '<div class="edit"></div>' +
            '</div>' +
            '</div>' +
            '</div>';
        return str;
    }
    function homeworkShow(opt) {
        var str = '<div style="background: #fff;" class="editSection">' +
            '<div class="fl" style="margin: 20px 0 0 0;text-align: left">' +
            opt+
            '</div>' +
            '</div>';
        return str;
    }
    function reportShow(opt) {
        var str = '<div style="background: #fff;" class="editSection">' +
            '<div class="fl" style="margin: 20px 0 0 0;text-align: left;padding-left: 20px;width: auto;">' +
            opt+
            '</div>' +
            '</div>';
        return str;
    }
    function saveImage() {
        return '<div class="saveImgBg"></div><div class="popup saveImageBox" style="display: block;top: 30%;">' +
            '<div class="popup_box">' +
            '<div style="text-align: center" class="popup_contenthead">保存镜像<img class="popup_img imageClose" src="pc/images/ico_alertDel.png"></div>' +
            '<div class="popup_content" style="min-height: 128px;margin: 0 auto;padding: 0;">' +
            '<div class="hideBox"><label>覆盖原有镜像:&ensp;</label>' +
            '<span class="form-control form-controls" style="box-shadow: none;">' +
            '<span  data-value="1" class="type radioc radioCheck2">是</span>' +
            '<span  data-value="2" class="type radioc">否</span>' +
            '</span>' +
            '<div class="clear"></div>' +
            '</div>'+
            '<div style="margin-left: 86px;margin-top: 47px;    margin-bottom: 0;display: none;" class="inputRight inBox fl"><label for="imgName">镜像名称:&ensp;</label>' +
            '<input type="text" class="publicText" id="imgName">' +
            '</div>' +
            '</div>' +
            '<div class="popup_btn">' +
            '<a  class="popup_confirm exportBtn saveImgTrue publicBtn hover-btn">确定</a>' +
            '<a class="popup_close exportCancle imageClose ">取消</a>' +
            '</div>' +
            '<div class="clear"></div>' +
            '</div>' +
            '</div>';
    }
    function testDocModels() {
        return '<div id="layoutSub">' +
            '<header id="labTitle">' +
            '<h4 class="fl saveLabs">保存</h4>' +
            '<img class="closeLab" src="pc/images/ico_alertDel.png">' +
            '</header>' +
            '<div id="LabEditormds">' +
            '<textarea style="display:none;"></textarea>' +
            '</div>' +
            '</div>';
    }
    function shearModel() {
        return '<div class="modal" id="clipboard-modal" tabindex="-1" role="dialog" style="display: block;">' +
            '<div class="modal-dialog" role="document">' +
            '<div class="modal-content">' +
            '<div class="modal-header">' +
            '<img class="alert_img shearClose" src="pc/images/ico_alertDel.png"></span>' +
            '<h4 class="modal-title">剪切板</h4>' +
            '</div>' +
            '<div class="modal-body">' +
            '<div>' +
            '<strong>复制外部内容到实验环境内：</strong>粘贴内容到下方输入框，点击‘保存’在实验环境中粘贴。' +
            '</div>' +
            '<textarea maxlength="20000" class="maxLimit" id="praseArea"></textarea>' +
            '</div>' +
            '<div class="modal-footer">' +
            '<button class="  clipboard-copy-btn publicBtn" type="button">保存</button>' +
            '<button class="  shearClose publicBtn" type="button" data-dismiss="modal">关闭</button>' +
            '</div>' +
            '</div>' +
            '</div>' +
            '</div>';
    }

    var myCourse = {
        address:'',
        init:function(){
            this.bindEvent();
        },
        bindEvent:function(){
            var self = this;
            self.getData();
            // 返回
            self.testEditor("MarEditormd");
            $(".looktg").attr("data-url",result.paramData.pageName);
            $(".looktg").off("click").click(function () {
                var json = JSON.stringify({
                    "pageName": $(this).attr("data-url"),
                    "paramData": {
                        "some": result.paramData.some
                    }
                });
                window.location.href = "skipPage?jsonStr=" + json;
            });
        },
        getImage:function (mark) {
            var self = this;
            var flag = true;
            if(mark != undefined){
                flag = mark;
            }
            $.ajax({
                type: "get",
                url: "image/list",
                data:{"isInitial":flag},
                async: true,
                success: function(msg) {
                    if(msg.code == 200) {
                        $("#oneImage").empty();
                        if(msg.data.length != 0) {
                            //列表
                            var tabel = "";
                            $.map(msg.data, function(opt) {
                                tabel += "<option value='"+ opt.id +"'>"+ opt.name +"</option>";
                            });
                            $("#oneImage").append(tabel);
                        }
                    } else {
                        Alert1.content = msg.message;
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }

                }
            });
        },
        getAllImage:function () {
            var self = this;
            $.ajax({
                type: "get",
                url: "cluster/listByAllocate",
                async: true,
                success: function(msg) {
                    if(msg.code == 200) {
                        $("#images").empty();
                        if(msg.data.length != 0) {
                            //列表
                            var tabel = "";
                            $.map(msg.data, function(opt) {
                                tabel += "<option value='"+ opt.id +"'>"+ opt.name +"</option>";
                            });
                            $("#images").append(tabel);
                        }
                    } else {
                        Alert1.content = msg.message;
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }

                }
            });
        },
        allocateEvent:function (chapterId) {
            var self = this;
            $.ajax({
                type: "get",
                url: "course/queryImageAllocate",
                data: {"chapterId": chapterId},
                async: true,
                success: function (msg) {
                    loading1.hide();
                    if (msg.code == 200) {
                        if (msg.data.length != 0 && msg.data != undefined && msg.data != null) {
                            var arrImg = [];
                            var flag = true;
                            for(var i = 0;i < msg.data.length;i++){
                                if(msg.data[i].broken!=undefined){
                                    arrImg.push(msg.data[i].broken);
                                }
                            }
                            if(arrImg.length!=0){
                                if(arrImg.indexOf(false) != -1){
                                    flag = true;
                                }else{
                                    flag = false;
                                }
                            }else{
                                flag = true;
                            }
                            if(flag){
                                if (msg.data.length == 1) {
                                    var flag = true;
                                    var clusterId;
                                    var imageId;
                                    var json = {};
                                    var url = '';
                                    var type = 0;
                                    var flavor='';
                                    if(msg.data[0].cluster!=true){
                                        // json.cluster = false;
                                        json.imageId = msg.data[0].imageId;
                                        imageId = msg.data[0].imageId;
                                        flavor = msg.data[0].flavor;
                                        url = "image/desktop";
                                        type = 1;
                                    }else{
                                        // json.cluster = true;
                                        json.clusterId = msg.data[0].clusterId;
                                        clusterId = msg.data[0].clusterId;
                                        type = 2;
                                        flavor = msg.data[0].flavor;
                                        url = "cluster/desktop";
                                    }
                                    if(flag){
                                        loading1.show();
                                        $.ajax({
                                            type: "get",
                                            url: url,
                                            data: json,
                                            async: true,
                                            success: function(msg) {
                                                loading1.hide();
                                                if(msg.code == 200) {
                                                    $(".virEnvirmentBox").remove();
                                                    $("#layoutSub").remove();
                                                    $("#virtualBox").remove();
                                                    $(".sftpBox").remove();
                                                    $(".navSideBar").remove();
                                                    $(".modal").remove();
                                                    $(".mbm").hide();
                                                    $(".packDown").remove();
                                                    $("#ifMain",parent.document).css({"position":"fixed","left":0,"top":0,"z-index":100});
                                                    $("body").css("overflow","hidden");
                                                    $(".virEnvirmentBox").remove();
                                                    $("body").append('<div class="virEnvirmentBox" style="width: 100%;">' +
                                                        '<div class="titleBox">' +
                                                        '<div title="关闭" class="fr cancelBtn "><img src="pc/images/ico_shareClose.png" alt="关闭"></div>' +
                                                        '<div class="configBox">' +
                                                        '<ul>' +
                                                        '</ul>' +
                                                        '</div>' +
                                                        '</div>' +
                                                        '</div>' +
                                                        '<div class="navSideBar">' +
                                                        '<div data-value="0" class="closeSide">' +
                                                        '工具栏' +
                                                        '</div>' +
                                                        '<div class="toolsBox">' +
                                                        '<ul>' +
                                                        '<li class="relink">刷新</li>' +
                                                        '<li class="exchangeBtn">重选配置</li>' +
                                                        '<li class="saveImg">保存镜像</li>' +
                                                        '<li class="line"></li>' +
                                                        '<li class="sftp">SFTP工具</li>' +
                                                        '<li class="shearBoardBtn">剪切板</li>' +
                                                        '<li class="line virAfter"></li>' +
                                                        '</ul>' +
                                                        '</div>' +
                                                        '</div>'+
                                                        '<div class="sftpBox">' +
                                                        '<div class="sftpContentBox">' +
                                                        '<header>' +
                                                        'SFTP工具' +
                                                        '<img class="closeSftp" src="pc/images/ico_alertDel.png">' +
                                                        '</header>' +
                                                        '<div class="sftpContent">' +
                                                        '<div>' +
                                                        '<div>您可以使用SFTP工具上传、下载文件：</div>' +
                                                        '<div>SFTP访问的地址为 <i class="blue blueHtml"></i> 端口号为 <i class="blue blueHtml2"></i></div>' +
                                                        '<div>用户名： <i class="blue">root</i>&ensp;   密码： <i class="blue">root</i> </div>' +
                                                        '<hr>' +
                                                        '<h4>使用说明</h4>' +
                                                        '<div class="marg">1.请先下载SFTP工具&emsp;<a href="upload/pscp/psftp_64.exe" download> <img class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down64.png"> </a>&emsp;&emsp;&emsp;<a href="upload/pscp/psftp_32.exe" download> <img  class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down32.png"> </a></div>' +
                                                        '<div class="marg">2.使用登陆命令   <i class="grayBg">open username@host post</i></div>' +
                                                        '<div class="marg">说明：username为用户名 host 为主机地址，post为端口号。</div>' +
                                                        '<div class="marg">3.填写密码进入SFTP环境。</div>' +
                                                        '<div class="marg">4.上传命令   <i class="grayBg">put dir/something.txt  dir/another.txt  </i></div>' +
                                                        '<div class="marg">说明：dir/something.txt 为用户当前环境的地址+文件。dir/another.txt为虚拟环境的地址加文件。</div>' +
                                                        '<div class="marg">例如：命令 put D:/bigdata.sql  /home/bigdata.sql  则是把本地D盘的bigdata.sql 文件上传至虚拟环境home 目录。</div>' +
                                                        '<div class="marg">5.下载命令   <i class="grayBg">get  dir/something.txt   dir/another.txt </i></div>' +
                                                        '<div class="marg">说明：dir/something.txt 为虚拟环境的地址加文件。dir/another.txt用户当前环境的地址+文件。</div>' +
                                                        '<div class="marg">例如：命令 get /home/bigdata.sql  E:/bigdata.sql  则是把虚拟环境home 目录的bigdata.sql 文件下载至的本地E盘。</div>' +
                                                        '<div class="publicBtn fr closeSftp ">确定</div>' +
                                                        '</div>' +
                                                        '</div>' +
                                                        '</div>' +
                                                        '</div>'+
                                                        '<div id="virtualBox">' +
                                                        '</div>' +
                                                        '</div>');
                                                    $("#virtualBox").height($(window).height() - 40);
                                                    $(".contentSection").height($(window).height() -  40);
                                                    $(".navSideBar").height($(window).height() -  40);
                                                    $(window).resize(function() {
                                                        $("#virtualBox").height($(window).height() -  40);
                                                        $(".contentSection").height($(window).height() -  40);
                                                        $(".navSideBar").height($(window).height() -  40);
                                                    });
                                                    //编辑器
                                                    $("body").append(testDocModels());
                                                    var testEditors = editormd('LabEditormds', {
                                                        width     : '100%',
                                                        height    : 480,
                                                        toc       : true,
                                                        todoList  : true,
                                                        path      : 'pc/js/extends/lib/',
                                                        watch:false,
                                                        tex:true,
                                                        saveHTMLToTextarea : true,
                                                        imageUpload : true,
                                                        imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                                        imageUploadURL : "editormdPic/",
                                                        flowChart: true,
                                                        sequenceDiagram: true,
                                                        dialogLockScreen : false,
                                                        dialogShowMask : true,
                                                        dialogDraggable : false,
                                                        dialogMaskOpacity : 0.4,
                                                        dialogMaskBgColor : "#000",
                                                        toolbarIcons : function() {
                                                            return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                                        }
                                                    });
                                                    $("#LabEditormds textarea").val($("#MarEditormd textarea").val());
                                                    $(".closeLab").off("click").click(function () {
                                                        $("#layoutSub").hide();
                                                        $("body").append("<img src=\"pc/images/ico_labEditBtn.png\" class=\"packDown\" >");
                                                        $(".packDown").off("click").click(function () {
                                                            $("#layoutSub").show();
                                                            var val =  $("#LabEditormds textarea").val();
                                                            testEditors = editormd('LabEditormds', {
                                                                width     : '100%',
                                                                height    : 480,
                                                                toc       : true,
                                                                todoList  : true,
                                                                path      : 'pc/js/extends/lib/',
                                                                watch:false,
                                                                saveHTMLToTextarea : true,
                                                                imageUpload : true,
                                                                tex:true,
                                                                imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                                                imageUploadURL : "editormdPic/",
                                                                flowChart: true,
                                                                sequenceDiagram: true,
                                                                dialogLockScreen : false,
                                                                dialogShowMask : true,
                                                                dialogDraggable : false,
                                                                dialogMaskOpacity : 0.4,
                                                                dialogMaskBgColor : "#000",
                                                                toolbarIcons : function() {
                                                                    return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                                                }
                                                            });
                                                            $("#LabEditormds textarea").val(val);
                                                            $(this).remove();
                                                        });
                                                    });
                                                    var div1 = document.getElementById("layoutSub");
                                                    var div2 = document.getElementById("labTitle");
                                                    div2.onmousedown = function(e){
                                                        var e = e || window.event;
                                                        var x = e.clientX - div1.offsetLeft;
                                                        var y = e.clientY - div1.offsetTop;
                                                        if(e.preventDefault){
                                                            e.preventDefault();
                                                        }
                                                        else{
                                                            e.returnValue = false;
                                                        }
                                                        document.onmousemove = function(e){
                                                            var e = e || window.event;
                                                            if(e.preventDefault){
                                                                e.preventDefault();
                                                            }
                                                            else{
                                                                e.returnValue = false;
                                                            }
                                                            var wid = e.clientX - x ;
                                                            var hei = e.clientY - y ;
                                                            div1.style.left = wid + "px";
                                                            div1.style.top = hei + "px";
                                                        }
                                                    };
                                                    document.onmouseup = function(e){
                                                        var e = e || event;
                                                        document.onmousemove = null;
                                                        if(e.preventDefault){
                                                            e.preventDefault();
                                                        }
                                                        else{
                                                            e.returnValue = false;
                                                        }
                                                    };
                                                    // 剪切板
                                                    $(".shearBoardBtn").off("click").click(function () {
                                                        var string = shearModel();
                                                        $("#clipboard-modal").remove();
                                                        $("body").append(string);
                                                        maxLengthLimit.init("maxLimit");
                                                        $(".shearClose").off("click").click(function () {
                                                            $(".modal").remove();
                                                        });
                                                        $(".clipboard-copy-btn").off("click").click(function () {
                                                            loading1.show();
                                                            var jsonStr = JSON.stringify({"content":$("#praseArea").val(),"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))});
                                                            $.ajax({
                                                                type: "post",
                                                                url: "desktop/clipboard",
                                                                data:jsonStr,
                                                                async: true,
                                                                dataType:'json',
                                                                contentType:'application/json',
                                                                success: function (msg) {
                                                                    loading1.hide();
                                                                    if (msg.code == "200") {
                                                                        $(".modal").remove();
                                                                        Alert1.content = "保存成功，请在实验环境中粘贴内容";
                                                                        Alert1.init();
                                                                        Alert1.show();
                                                                    }else{
                                                                        Alert1.content = msg.message;
                                                                        Alert1.init();
                                                                        Alert1.show();
                                                                    }
                                                                }
                                                            });
                                                        });
                                                    });

                                                    // SFTP
                                                    $(".sftp").off("click").click(function () {
                                                        $(".sftpBox").show();
                                                        // 获取sftp地址和端口
                                                        $.ajax({
                                                            type: "get",
                                                            url: "desktop/ftp",
                                                            data: {"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                                            async: true,
                                                            dataType: 'json',
                                                            contentType: 'application/json',
                                                            success: function (msg) {
                                                                if (msg.code == "200") {
                                                                    var arr = msg.data.ftp.split(":");
                                                                    $(".blueHtml").html(arr[0]);
                                                                    $(".blueHtml2").html(arr[1]);
                                                                }else{
                                                                    Alert1.content = msg.message;
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                    return false;
                                                                }
                                                            }
                                                        });
                                                    });
                                                    $(".closeSftp").off("click").click(function () {
                                                        $(".sftpBox").hide();
                                                    });
                                                    //刷新
                                                    $(".relink").off("click").click(function () {
                                                        var url = $(".virMBox[data-value=1]").attr("src");
                                                        $(".virMBox[data-value=1]").attr("src",url);
                                                    });
                                                    // 工具栏
                                                    $(".closeSide").off("click").click(function () {
                                                        if($(this).attr("data-value") == 0){
                                                            $(this).attr("data-value",1);
                                                            $(".navSideBar").animate({
                                                                "right":"-120px"
                                                            },300);
                                                        }else{
                                                            $(this).attr("data-value",0);
                                                            $(".navSideBar").animate({
                                                                "right":"0"
                                                            },300);
                                                        }
                                                    });
                                                    // 实验手册保存
                                                    $(".saveLabs").off("click").click(function(){
                                                        var json = JSON.stringify({"htmlStr":$("#LabEditormds .editormd-preview").html(),"chapterId":chapterId,"testNameHtml":escape($("#LabEditormds textarea").val()),"courseMaterialNameHtml":'',"mark":2});
                                                        if($("#LabEditormds textarea").val()!=''&& $("#LabEditormds .markdown-body").html() == ''){
                                                            Alert1.content = "请点击预览查看编写效果";
                                                            Alert1.init();
                                                            Alert1.show();
                                                        }else{
                                                            $.ajax({
                                                                type: 'post',
                                                                url: 'addChapterMaterialOrTest',
                                                                async: true,
                                                                data: {
                                                                    "jsonStr": json
                                                                },
                                                                success: function (msg) {
                                                                    msg = JSON.parse(msg);
                                                                    if (msg.result == "success") {
                                                                        Alert1.content = "保存成功";
                                                                        Alert1.init();
                                                                        Alert1.show();
                                                                        $(".checkBtn").attr("data-src",self.address+msg.filename);
                                                                        $(".checkBtn").siblings("b").attr("data-src",self.address+msg.filename);
                                                                    } else {
                                                                        if (msg.failMsg != undefined) {
                                                                            Alert1.content = msg.failMsg;
                                                                        } else {
                                                                            Alert1.content = "添加章节失败";
                                                                        }
                                                                        Alert1.init();
                                                                        Alert1.show();
                                                                    }
                                                                }
                                                            });
                                                        }
                                                    });
                                                    // 返回上一页
                                                    $(".cancelBtn").off("click").click(function() {
                                                        confirm1.content = "确定退出实验环境吗？";
                                                        confirm1.success = function () {
                                                            $("#ifMain",parent.document).attr("style","");
                                                            $(".virEnvirmentBox").remove();
                                                            self.testEditor("MarEditormd");
                                                            $("#MarEditormd textarea").val($("#LabEditormds textarea").val());
                                                            $("#MarEditormd .markdown-body").html('');
                                                            $("#layoutSub").remove();
                                                            $("#virtualBox").remove();
                                                            $(".sftpBox").remove();
                                                            $(".navSideBar").remove();
                                                            $(".modal").remove();
                                                            $(".packDown").remove();
                                                            $(".mbm").hide();

                                                            $("body").css("overflow","inherit");
                                                        };
                                                        confirm1.init();
                                                        confirm1.show();
                                                    });
                                                    $(".popup,.mb").hide();
                                                    $(".come,.imageBox").show();
                                                    $(".imagesBox").hide();
                                                    $(".types").removeClass("radioChecks");
                                                    $(".types").eq(0).addClass("radioChecks");
                                                    $("#oneConfig").val('2,2');
                                                    self.getImage(true);
                                                    // 配置
                                                    var str = '';
                                                    var str1 = '';
                                                    if(msg.data.masterImageId != undefined){
                                                        str += "<li data-value='1' data-url='"+ msg.data.masterDesktopUrl +"'  data-containerid="+ msg.data.masterContainerId +">主节点(当前)</li>";
                                                        str += "<li data-value='0' data-url='"+ msg.data.firstSlaveDesktopUrl +"'  data-containerid="+ msg.data.firstSlaveContainerId +">从节点1</li>";
                                                        str += "<li data-value='0' data-url='"+ msg.data.secondSlaveDesktopUrl +"'  data-containerid="+ msg.data.secondSlaveContainerId +">从节点2</li>";
                                                        $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='"+ msg.data.masterImageId +"' data-value='1' data-containerid="+ msg.data.masterContainerId  +" class=\"virMBox\" src="+msg.data.masterDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                                        $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='"+ msg.data.firstSlaveImageId +"'  data-value='0' data-containerid="+ msg.data.firstSlaveContainerId +" class=\"virMBox\" src="+msg.data.firstSlaveDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                                        $("#virtualBox").append("<iframe name='virMBoxes'  data-imageid='"+ msg.data.secondSlaveImageId +"' data-value='0' data-containerid="+ msg.data.secondSlaveContainerId +" class=\"virMBox\" src="+msg.data.secondSlaveDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                                        // $(".configBox>ul").html(str);
                                                        str1 += "<li type='1' class='nav mainVir' data-value='1' data-url='"+ msg.data.masterDesktopUrl +"'  data-containerid="+ msg.data.masterContainerId +">主节点</li>";
                                                        str1 += "<li type='2' class='nav subVir' data-value='0' data-url='"+ msg.data.firstSlaveDesktopUrl +"'  data-containerid="+ msg.data.firstSlaveContainerId +">从节点1</li>";
                                                        str1 += "<li type='2' class='nav thVir' data-value='0' data-url='"+ msg.data.secondSlaveDesktopUrl +"'  data-containerid="+ msg.data.secondSlaveContainerId +">从节点2</li>";
                                                        $(".virAfter").after(str1);
                                                        startWebSocket(msg.data.masterContainerId);
                                                        startWebSocket(msg.data.firstSlaveContainerId);
                                                        startWebSocket(msg.data.secondSlaveContainerId);
                                                        $(".saveImg").html("保存集群");
                                                    }else{
                                                        $(".saveImg").html("保存镜像");
                                                        // str += "<li data-value='1' data-url='"+ msg.data.desktopUrl +"'  data-containerid="+ msg.data.containerId +">单节点(当前)</li>";
                                                        $("#virtualBox").append("<iframe   name='virMBoxes' data-imageid='"+ msg.data.imageId +"' data-value='1' data-containerid="+ msg.data.containerId +" class=\"virMBox\" src="+msg.data.desktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                                        startWebSocket(msg.data.containerId);
                                                    }
                                                    $(".mainVir").css({"background":'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                    $(".mainVir").off("click").click(function () {
                                                        $(".nav").attr("style",'');
                                                        $(".nav").attr("data-value",'0');
                                                        $(this).css({"background":'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                        $(this).attr("data-value","1");
                                                        $(".virMBox").attr("data-value","0").hide();
                                                        $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                    });
                                                    $(".subVir").off("click").click(function () {
                                                        $(".nav").attr("style",'');
                                                        $(".nav").attr("data-value",'0');
                                                        $(this).css({"background":'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                        $(this).attr("data-value","1");
                                                        $(".virMBox").attr("data-value","0").hide();
                                                        $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                    });
                                                    $(".thVir").off("click").click(function () {
                                                        $(".nav").attr("style",'');
                                                        $(".nav").attr("data-value",'0');
                                                        $(this).css({"background":'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                        $(this).attr("data-value","1");
                                                        $(".virMBox").attr("data-value","0").hide();
                                                        $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                    });

                                                    // 获取sftp地址和端口
                                                    $.ajax({
                                                        type: "get",
                                                        url: "desktop/ftp",
                                                        data: {"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                                        async: true,
                                                        dataType: 'json',
                                                        contentType: 'application/json',
                                                        success: function (msg) {
                                                            if (msg.code == "200") {
                                                                var arr = msg.data.ftp.split(":");
                                                                $(".blueHtml").html(arr[0]);
                                                                $(".blueHtml2").html(arr[1]);
                                                            }else{
                                                                Alert1.content = msg.message;
                                                                Alert1.init();
                                                                Alert1.show();
                                                                return false;
                                                            }
                                                        }
                                                    });
                                                    //重新选择镜像
                                                    $(".exchangeBtn").off("click").click(function () {
                                                        self.testEditor("LabEditormd");
                                                        $("#MarEditormd textarea").val($("#LabEditormds textarea").val());
                                                        self.allocateEvents(chapterId);
                                                    });
                                                    //保存镜像
                                                    $(".saveImg").off("click").click(function () {
                                                        if ($(".virMBox").length == 1) {
                                                            $("body").append(saveImage());
                                                            $(".radioc").off("click").click(function () {
                                                                $(".radioc").removeClass("radioCheck2");
                                                                $(this).addClass("radioCheck2");
                                                                if ($(this).attr("data-value") == 2) {
                                                                    $(".inBox ").show();
                                                                } else {
                                                                    $(".inBox ").hide();
                                                                }
                                                            });
                                                            $(".imageClose").off("click").click(function () {
                                                                $(".saveImgBg").remove();
                                                                $(".saveImageBox").remove();
                                                            });
                                                            $(".saveImgTrue").off("click").click(function () {
                                                                if ($("#imgName").val() == "" && $(".radioCheck2").attr("data-value") == 2) {
                                                                    Alert1.content = "请输入镜像名称";
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                } else {
                                                                    if ($(".virMBox").length == 1) {
                                                                        if ($(".radioCheck2").attr("data-value") == 1) {
                                                                            loading1.show();
                                                                            var json = JSON.stringify({
                                                                                "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                                                                "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                            });
                                                                            $.ajax({
                                                                                type: "post",
                                                                                url: "image/cover",
                                                                                dataType: 'json',
                                                                                contentType: 'application/json',
                                                                                data: json,
                                                                                async: true,
                                                                                success: function (msg) {
                                                                                    loading1.hide();
                                                                                    if (msg.code == 200) {
                                                                                        loading1.show();
                                                                                        var json = {"chapterIds": [chapterId]};
                                                                                        json.courseId = 0;
                                                                                        json.cluster = false;
                                                                                        json.imageId = msg.data.imageId;
                                                                                        $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                        json.flavor = flavor;
                                                                                        json = JSON.stringify(json);
                                                                                        $.ajax({
                                                                                            type: "post",
                                                                                            url: "image/allocate/confirm",
                                                                                            data: json,
                                                                                            dataType: "JSON",
                                                                                            contentType: 'application/json',
                                                                                            async: true,
                                                                                            success: function (msg) {
                                                                                                loading1.hide();
                                                                                                if (msg.code == 200) {
                                                                                                    Alert1.content = "保存镜像成功";
                                                                                                    $(".saveImgBg").remove();
                                                                                                    $(".saveImageBox").remove();
                                                                                                    var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                    $(".virMBox[data-value=1]").attr("src", url);
                                                                                                    Alert1.init();
                                                                                                    Alert1.show();
                                                                                                } else {
                                                                                                    Alert1.content = msg.message;
                                                                                                    Alert1.init();
                                                                                                    Alert1.show();
                                                                                                    return false;
                                                                                                }

                                                                                            },
                                                                                            error: function () {
                                                                                                loading1.hide();
                                                                                            }
                                                                                        });
                                                                                    } else {
                                                                                        Alert1.content = msg.message;
                                                                                        Alert1.init();
                                                                                        Alert1.show();
                                                                                        return false;
                                                                                    }
                                                                                }
                                                                            });
                                                                        } else {
                                                                            var json = JSON.stringify({
                                                                                "imageName": $("#imgName").val(),
                                                                                "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                            });
                                                                            loading1.show();
                                                                            $.ajax({
                                                                                type: "post",
                                                                                url: "image/create",
                                                                                dataType: 'json',
                                                                                contentType: 'application/json',
                                                                                data: json,
                                                                                async: true,
                                                                                success: function (msg) {
                                                                                    loading1.hide();
                                                                                    if (msg.code == 200) {
                                                                                        loading1.show();
                                                                                        var json = {"chapterIds": [chapterId]};
                                                                                        json.courseId = 0;
                                                                                        json.cluster = false;
                                                                                        json.imageId = msg.data.imageId;
                                                                                        json.flavor = flavor;
                                                                                        $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                        json = JSON.stringify(json);
                                                                                        $.ajax({
                                                                                            type: "post",
                                                                                            url: "image/allocate/confirm",
                                                                                            data: json,
                                                                                            dataType: "JSON",
                                                                                            contentType: 'application/json',
                                                                                            async: true,
                                                                                            success: function (msg) {
                                                                                                loading1.hide();
                                                                                                if (msg.code == 200) {
                                                                                                    Alert1.content = "保存镜像成功";
                                                                                                    $(".saveImgBg").remove();
                                                                                                    $(".saveImageBox").remove();
                                                                                                    var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                    $(".virMBox[data-value=1]").attr("src", url);
                                                                                                    Alert1.init();
                                                                                                    Alert1.show();
                                                                                                } else {
                                                                                                    Alert1.content = msg.message;
                                                                                                    Alert1.init();
                                                                                                    Alert1.show();
                                                                                                    return false;
                                                                                                }

                                                                                            },
                                                                                            error: function () {
                                                                                                loading1.hide();
                                                                                            }
                                                                                        });
                                                                                    } else {
                                                                                        Alert1.content = msg.message;
                                                                                        Alert1.init();
                                                                                        Alert1.show();
                                                                                        return false;
                                                                                    }
                                                                                }
                                                                            });
                                                                        }
                                                                    }
                                                                }
                                                            });
                                                        }else{
                                                            loading1.show();
                                                            var json = JSON.stringify({
                                                                "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                                                "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                            });
                                                            $.ajax({
                                                                type: "post",
                                                                url: "image/cover",
                                                                dataType: 'json',
                                                                contentType: 'application/json',
                                                                data: json,
                                                                async: true,
                                                                success: function (msg) {
                                                                    loading1.hide();
                                                                    if (msg.code == 200) {
                                                                        var json = {"chapterIds": [chapterId]};
                                                                        json.courseId = 0;
                                                                        json.cluster = false;
                                                                        json.imageId = msg.data.imageId;
                                                                        json.flavor = flavor;
                                                                        $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                        json = JSON.stringify(json);
                                                                        $(".saveImgBg").remove();
                                                                        $(".saveImageBox").remove();
                                                                        var json = JSON.stringify({
                                                                            "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                                            "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                                            "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                                        });
                                                                        $.ajax({
                                                                            type: "post",
                                                                            url: "cluster/create",
                                                                            dataType: 'json',
                                                                            contentType: 'application/json',
                                                                            data: json,
                                                                            async: true,
                                                                            success: function (msg) {
                                                                                loading1.hide();
                                                                                if (msg.code == 200) {
                                                                                    var json = {"chapterIds": [chapterId]};
                                                                                    json.courseId = 0;
                                                                                    json.cluster = true;
                                                                                    json.clusterId = msg.data.clusterId;
                                                                                    json.flavor = flavor;
                                                                                    json = JSON.stringify(json);
                                                                                    loading1.show();
                                                                                    $.ajax({
                                                                                        type: "post",
                                                                                        url: "image/allocate/confirm",
                                                                                        data: json,
                                                                                        dataType: "JSON",
                                                                                        contentType: 'application/json',
                                                                                        async: true,
                                                                                        success: function (msg) {
                                                                                            loading1.hide();
                                                                                            if (msg.code == 200) {
                                                                                                Alert2.content = "保存集群成功";
                                                                                                Alert2.init();
                                                                                                Alert2.show();
                                                                                                $(".saveImgBg").remove();
                                                                                                $(".saveImageBox").remove();
                                                                                                var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                $(".virMBox[data-value=1]").attr("src", url);
                                                                                            } else {
                                                                                                Alert1.content = msg.message;
                                                                                                Alert1.init();
                                                                                                Alert1.show();
                                                                                                return false;
                                                                                            }

                                                                                        },
                                                                                        error: function () {
                                                                                            loading1.hide();
                                                                                        }
                                                                                    });
                                                                                } else {
                                                                                    Alert1.content = msg.message;
                                                                                    Alert1.init();
                                                                                    Alert1.show();
                                                                                    return false;
                                                                                }
                                                                            }
                                                                        });

                                                                    } else {
                                                                        confirm1.content = "不允许覆盖公有的镜像，确定创建新的镜像吗？";
                                                                        confirm1.success = function () {
                                                                            $("body").append(saveImage());
                                                                            $(".radioc").eq(0).removeClass("radioCheck2");
                                                                            $(".radioc").eq(1).addClass("radioCheck2");
                                                                            $(".inBox").show();
                                                                            $(".hideBox").hide();
                                                                            $(".radioc").off("click").click(function () {
                                                                                $(".radioc").removeClass("radioCheck2");
                                                                                $(this).addClass("radioCheck2");
                                                                                if($(this).attr("data-value") == 2){
                                                                                    $(".inBox ").show();
                                                                                }else{
                                                                                    $(".inBox ").hide();
                                                                                }
                                                                            });
                                                                            $(".imageClose").off("click").click(function () {
                                                                                $(".saveImgBg").remove();
                                                                                $(".saveImageBox").remove();
                                                                            });
                                                                            $(".saveImgTrue").off("click").click(function () {
                                                                                if ($("#imgName").val() == ""&&$(".radioCheck2").attr("data-value") == 2) {
                                                                                    Alert1.content = "请输入镜像名称";
                                                                                    Alert1.init();
                                                                                    Alert1.show();
                                                                                } else {
                                                                                    var json = JSON.stringify({
                                                                                        "imageName": $("#imgName").val(),
                                                                                        "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                                    });
                                                                                    loading1.show();
                                                                                    $.ajax({
                                                                                        type: "post",
                                                                                        url: "image/create",
                                                                                        dataType: 'json',
                                                                                        contentType: 'application/json',
                                                                                        data: json,
                                                                                        async: true,
                                                                                        success: function (msg) {
                                                                                            loading1.hide();
                                                                                            if (msg.code == 200) {
                                                                                                loading1.hide();
                                                                                                var json = {"chapterIds": [chapterId]};
                                                                                                json.courseId = 0;
                                                                                                json.cluster = false;
                                                                                                json.imageId = msg.data.imageId;
                                                                                                json.flavor = flavor;
                                                                                                $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                                json = JSON.stringify(json);
                                                                                                var json = JSON.stringify({
                                                                                                    "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                                                                    "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                                                                    "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                                                                });
                                                                                                $.ajax({
                                                                                                    type: "post",
                                                                                                    url: "cluster/create",
                                                                                                    dataType: 'json',
                                                                                                    contentType: 'application/json',
                                                                                                    data: json,
                                                                                                    async: true,
                                                                                                    success: function (msg) {
                                                                                                        loading1.hide();
                                                                                                        if (msg.code == 200) {
                                                                                                            var json = {"chapterIds": [chapterId]};
                                                                                                            json.courseId = 0;
                                                                                                            json.cluster = true;
                                                                                                            json.clusterId = msg.data.clusterId;
                                                                                                            json.flavor = flavor;
                                                                                                            json = JSON.stringify(json);
                                                                                                            loading1.show();
                                                                                                            $.ajax({
                                                                                                                type: "post",
                                                                                                                url: "image/allocate/confirm",
                                                                                                                data: json,
                                                                                                                dataType: "JSON",
                                                                                                                contentType: 'application/json',
                                                                                                                async: true,
                                                                                                                success: function (msg) {
                                                                                                                    loading1.hide();
                                                                                                                    if (msg.code == 200) {
                                                                                                                        Alert2.content = "保存集群成功";
                                                                                                                        Alert2.init();
                                                                                                                        Alert2.show();
                                                                                                                        $(".saveImgBg").remove();
                                                                                                                        $(".saveImageBox").remove();
                                                                                                                        var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                                        $(".virMBox[data-value=1]").attr("src", url);
                                                                                                                    } else {
                                                                                                                        Alert1.content = msg.message;
                                                                                                                        Alert1.init();
                                                                                                                        Alert1.show();
                                                                                                                        return false;
                                                                                                                    }

                                                                                                                },
                                                                                                                error: function () {
                                                                                                                    loading1.hide();
                                                                                                                }
                                                                                                            });
                                                                                                        } else {
                                                                                                            Alert1.content = msg.message;
                                                                                                            Alert1.init();
                                                                                                            Alert1.show();
                                                                                                            return false;
                                                                                                        }
                                                                                                    }
                                                                                                });
                                                                                                $(".saveImgBg").remove();
                                                                                                $(".saveImageBox").remove();
                                                                                            } else {
                                                                                                Alert1.content = msg.message;
                                                                                                Alert1.init();
                                                                                                Alert1.show();
                                                                                                return false;
                                                                                            }
                                                                                        }
                                                                                    });
                                                                                }
                                                                            });
                                                                        };
                                                                        confirm1.init();
                                                                        confirm1.show();
                                                                    }
                                                                }
                                                            });
                                                        }
                                                    });
                                                } else {
                                                    Alert1.content = msg.message;
                                                    Alert1.init();
                                                    Alert1.show();
                                                    return false;
                                                }

                                            },
                                            error:function () {
                                                loading1.hide();
                                            }
                                        });
                                    }
                                }else{
                                    var str = '<div style="margin-left: 160px;" class="inputRight fl"><label for="reCheck">镜像/集群名称:&ensp;</label>' +
                                        '<select type="text" class="publicSelect" id="reCheck">';
                                    $.map(msg.data,function (opt) {
                                        str+="<option data-flavor='"+ opt.flavor +"' data-clusterid='"+ opt.clusterId +"' data-cluster='"+ opt.cluster +"' data-imageid='"+ opt.imageId +"'>"+ opt.itemName +"</option>";
                                    });
                                    str+='</select>' +
                                        '</div>';
                                    confirm3.contenthead = "模版配置";
                                    confirm3.content = str;
                                    confirm3.success = function () {
                                        var flag = true;
                                        var clusterId;
                                        var imageId;
                                        var json = {};
                                        var url = '';
                                        var type = 0;
                                        var flavor='';
                                        var optionCheck = $("#reCheck").children("option:selected");
                                        if(optionCheck.attr("data-cluster")!="true"){
                                            // json.cluster = false;
                                            json.imageId = Number(optionCheck.attr("data-imageid"));
                                            imageId = Number(optionCheck.attr("data-imageid"));
                                            flavor = optionCheck.attr("data-flavor");
                                            url = "image/desktop";
                                            type = 1;
                                        }else{
                                            // json.cluster = true;
                                            json.clusterId = Number(optionCheck.attr("data-clusterid"));
                                            clusterId =Number(optionCheck.attr("data-clusterid"));
                                            type = 2;
                                            flavor = optionCheck.attr("data-flavor");
                                            url = "cluster/desktop";
                                        }
                                        if(flag){
                                            loading1.show();
                                            $.ajax({
                                                type: "get",
                                                url: url,
                                                data: json,
                                                async: true,
                                                success: function(msg) {
                                                    loading1.hide();
                                                    if(msg.code == 200) {
                                                        $(".virEnvirmentBox").remove();
                                                        $("#layoutSub").remove();
                                                        $("#virtualBox").remove();
                                                        $(".sftpBox").remove();
                                                        $(".navSideBar").remove();
                                                        $(".modal").remove();
                                                        $(".mbm").hide();
                                                        $(".packDown").remove();
                                                        $("#ifMain",parent.document).css({"position":"fixed","left":0,"top":0,"z-index":100});
                                                        $("body").css("overflow","hidden");
                                                        $(".virEnvirmentBox").remove();
                                                        $("body").append('<div class="virEnvirmentBox" style="width: 100%;">' +
                                                            '<div class="titleBox">' +
                                                            '<div title="关闭" class="fr cancelBtn "><img src="pc/images/ico_shareClose.png" alt="关闭"></div>' +
                                                            '<div class="configBox">' +
                                                            '<ul>' +
                                                            '</ul>' +
                                                            '</div>' +
                                                            '</div>' +
                                                            '</div>' +
                                                            '<div class="navSideBar">' +
                                                            '<div data-value="0" class="closeSide">' +
                                                            '工具栏' +
                                                            '</div>' +
                                                            '<div class="toolsBox">' +
                                                            '<ul>' +
                                                            '<li class="relink">刷新</li>' +
                                                            '<li class="exchangeBtn">重选配置</li>' +
                                                            '<li class="saveImg">保存镜像</li>' +
                                                            '<li class="line"></li>' +
                                                            '<li class="sftp">SFTP工具</li>' +
                                                            '<li class="shearBoardBtn">剪切板</li>' +
                                                            '<li class="line virAfter"></li>' +
                                                            '</ul>' +
                                                            '</div>' +
                                                            '</div>'+
                                                            '<div class="sftpBox">' +
                                                            '<div class="sftpContentBox">' +
                                                            '<header>' +
                                                            'SFTP工具' +
                                                            '<img class="closeSftp" src="pc/images/ico_alertDel.png">' +
                                                            '</header>' +
                                                            '<div class="sftpContent">' +
                                                            '<div>' +
                                                            '<div>您可以使用SFTP工具上传、下载文件：</div>' +
                                                            '<div>SFTP访问的地址为 <i class="blue blueHtml"></i> 端口号为 <i class="blue blueHtml2"></i></div>' +
                                                            '<div>用户名： <i class="blue">root</i>&ensp;   密码： <i class="blue">root</i> </div>' +
                                                            '<hr>' +
                                                            '<h4>使用说明</h4>' +
                                                            '<div class="marg">1.请先下载SFTP工具&emsp;<a href="upload/pscp/psftp_64.exe" download> <img class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down64.png"> </a>&emsp;&emsp;&emsp;<a href="upload/pscp/psftp_32.exe" download> <img  class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down32.png"> </a></div>' +
                                                            '<div class="marg">2.使用登陆命令   <i class="grayBg">open username@host post</i></div>' +
                                                            '<div class="marg">说明：username为用户名 host 为主机地址，post为端口号。</div>' +
                                                            '<div class="marg">3.填写密码进入SFTP环境。</div>' +
                                                            '<div class="marg">4.上传命令   <i class="grayBg">put dir/something.txt  dir/another.txt  </i></div>' +
                                                            '<div class="marg">说明：dir/something.txt 为用户当前环境的地址+文件。dir/another.txt为虚拟环境的地址加文件。</div>' +
                                                            '<div class="marg">例如：命令 put D:/bigdata.sql  /home/bigdata.sql  则是把本地D盘的bigdata.sql 文件上传至虚拟环境home 目录。</div>' +
                                                            '<div class="marg">5.下载命令   <i class="grayBg">get  dir/something.txt   dir/another.txt </i></div>' +
                                                            '<div class="marg">说明：dir/something.txt 为虚拟环境的地址加文件。dir/another.txt用户当前环境的地址+文件。</div>' +
                                                            '<div class="marg">例如：命令 get /home/bigdata.sql  E:/bigdata.sql  则是把虚拟环境home 目录的bigdata.sql 文件下载至的本地E盘。</div>' +
                                                            '<div class="publicBtn fr closeSftp ">确定</div>' +
                                                            '</div>' +
                                                            '</div>' +
                                                            '</div>' +
                                                            '</div>'+
                                                            '<div id="virtualBox">' +
                                                            '</div>' +
                                                            '</div>');
                                                        $("#virtualBox").height($(window).height() - 40);
                                                        $(".contentSection").height($(window).height() -  40);
                                                        $(".navSideBar").height($(window).height() -  40);
                                                        $(window).resize(function() {
                                                            $("#virtualBox").height($(window).height() -  40);
                                                            $(".contentSection").height($(window).height() -  40);
                                                            $(".navSideBar").height($(window).height() -  40);
                                                        });
                                                        //编辑器
                                                        $("body").append(testDocModels());
                                                        var testEditors = editormd('LabEditormds', {
                                                            width     : '100%',
                                                            height    : 480,
                                                            toc       : true,
                                                            todoList  : true,
                                                            path      : 'pc/js/extends/lib/',
                                                            watch:false,
                                                            tex:true,
                                                            saveHTMLToTextarea : true,
                                                            imageUpload : true,
                                                            imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                                            imageUploadURL : "editormdPic/",
                                                            flowChart: true,
                                                            sequenceDiagram: true,
                                                            dialogLockScreen : false,
                                                            dialogShowMask : true,
                                                            dialogDraggable : false,
                                                            dialogMaskOpacity : 0.4,
                                                            dialogMaskBgColor : "#000",
                                                            toolbarIcons : function() {
                                                                return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                                            }
                                                        });
                                                        $("#LabEditormds textarea").val($("#MarEditormd textarea").val());
                                                        $(".closeLab").off("click").click(function () {
                                                            $("#layoutSub").hide();
                                                            $("body").append("<img src=\"pc/images/ico_labEditBtn.png\" class=\"packDown\" >");
                                                            $(".packDown").off("click").click(function () {
                                                                $("#layoutSub").show();
                                                                var val =  $("#LabEditormds textarea").val();
                                                                testEditors = editormd('LabEditormds', {
                                                                    width     : '100%',
                                                                    height    : 480,
                                                                    toc       : true,
                                                                    todoList  : true,
                                                                    path      : 'pc/js/extends/lib/',
                                                                    watch:false,
                                                                    saveHTMLToTextarea : true,
                                                                    imageUpload : true,
                                                                    tex:true,
                                                                    imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                                                    imageUploadURL : "editormdPic/",
                                                                    flowChart: true,
                                                                    sequenceDiagram: true,
                                                                    dialogLockScreen : false,
                                                                    dialogShowMask : true,
                                                                    dialogDraggable : false,
                                                                    dialogMaskOpacity : 0.4,
                                                                    dialogMaskBgColor : "#000",
                                                                    toolbarIcons : function() {
                                                                        return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                                                    }
                                                                });
                                                                $("#LabEditormds textarea").val(val);
                                                                $(this).remove();
                                                            });
                                                        });
                                                        var div1 = document.getElementById("layoutSub");
                                                        var div2 = document.getElementById("labTitle");
                                                        div2.onmousedown = function(e){
                                                            var e = e || window.event;
                                                            var x = e.clientX - div1.offsetLeft;
                                                            var y = e.clientY - div1.offsetTop;
                                                            if(e.preventDefault){
                                                                e.preventDefault();
                                                            }
                                                            else{
                                                                e.returnValue = false;
                                                            }
                                                            document.onmousemove = function(e){
                                                                var e = e || window.event;
                                                                if(e.preventDefault){
                                                                    e.preventDefault();
                                                                }
                                                                else{
                                                                    e.returnValue = false;
                                                                }
                                                                var wid = e.clientX - x ;
                                                                var hei = e.clientY - y ;
                                                                div1.style.left = wid + "px";
                                                                div1.style.top = hei + "px";
                                                            }
                                                        };
                                                        document.onmouseup = function(e){
                                                            var e = e || event;
                                                            document.onmousemove = null;
                                                            if(e.preventDefault){
                                                                e.preventDefault();
                                                            }
                                                            else{
                                                                e.returnValue = false;
                                                            }
                                                        };
                                                        // 剪切板
                                                        $(".shearBoardBtn").off("click").click(function () {
                                                            var string = shearModel();
                                                            $("#clipboard-modal").remove();
                                                            $("body").append(string);
                                                            $(".shearClose").off("click").click(function () {
                                                                $(".modal").remove();
                                                            });
                                                            $(".clipboard-copy-btn").off("click").click(function () {
                                                                loading1.show();
                                                                var jsonStr = JSON.stringify({"content":$("#praseArea").val(),"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))});
                                                                $.ajax({
                                                                    type: "post",
                                                                    url: "desktop/clipboard",
                                                                    data:jsonStr,
                                                                    async: true,
                                                                    dataType:'json',
                                                                    contentType:'application/json',
                                                                    success: function (msg) {
                                                                        loading1.hide();
                                                                        if (msg.code == "200") {
                                                                            $(".modal").remove();
                                                                            Alert1.content = "保存成功，请在实验环境中粘贴内容";
                                                                            Alert1.init();
                                                                            Alert1.show();
                                                                        }else{
                                                                            Alert1.content = msg.message;
                                                                            Alert1.init();
                                                                            Alert1.show();
                                                                        }
                                                                    }
                                                                });
                                                            });
                                                        });

                                                        // SFTP
                                                        $(".sftp").off("click").click(function () {
                                                            $(".sftpBox").show();
                                                            // 获取sftp地址和端口
                                                            $.ajax({
                                                                type: "get",
                                                                url: "desktop/ftp",
                                                                data: {"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                                                async: true,
                                                                dataType: 'json',
                                                                contentType: 'application/json',
                                                                success: function (msg) {
                                                                    if (msg.code == "200") {
                                                                        var arr = msg.data.ftp.split(":");
                                                                        $(".blueHtml").html(arr[0]);
                                                                        $(".blueHtml2").html(arr[1]);
                                                                    }else{
                                                                        Alert1.content = msg.message;
                                                                        Alert1.init();
                                                                        Alert1.show();
                                                                        return false;
                                                                    }
                                                                }
                                                            });
                                                        });
                                                        $(".closeSftp").off("click").click(function () {
                                                            $(".sftpBox").hide();
                                                        });
                                                        //刷新
                                                        $(".relink").off("click").click(function () {
                                                            var url = $(".virMBox[data-value=1]").attr("src");
                                                            $(".virMBox[data-value=1]").attr("src",url);
                                                        });
                                                        // 工具栏
                                                        $(".closeSide").off("click").click(function () {
                                                            if($(this).attr("data-value") == 0){
                                                                $(this).attr("data-value",1);
                                                                $(".navSideBar").animate({
                                                                    "right":"-120px"
                                                                },300);
                                                            }else{
                                                                $(this).attr("data-value",0);
                                                                $(".navSideBar").animate({
                                                                    "right":"0"
                                                                },300);
                                                            }
                                                        });
                                                        // 实验手册保存
                                                        $(".saveLabs").off("click").click(function(){
                                                            var json = JSON.stringify({"htmlStr":$("#LabEditormds .editormd-preview").html(),"chapterId":chapterId,"testNameHtml":escape($("#LabEditormds textarea").val()),"courseMaterialNameHtml":'',"mark":2});
                                                            if($("#LabEditormds textarea").val()!=''&& $("#LabEditormds .markdown-body").html() == ''){
                                                                Alert1.content = "请点击预览查看编写效果";
                                                                Alert1.init();
                                                                Alert1.show();
                                                            }else{
                                                                $.ajax({
                                                                    type: 'post',
                                                                    url: 'addChapterMaterialOrTest',
                                                                    async: true,
                                                                    data: {
                                                                        "jsonStr": json
                                                                    },
                                                                    success: function (msg) {
                                                                        msg = JSON.parse(msg);
                                                                        if (msg.result == "success") {
                                                                            Alert1.content = "保存成功";
                                                                            Alert1.init();
                                                                            Alert1.show();
                                                                            $(".checkBtn").attr("data-src",self.address+msg.filename);
                                                                            $(".checkBtn").siblings("b").attr("data-src",self.address+msg.filename);
                                                                        } else {
                                                                            if (msg.failMsg != undefined) {
                                                                                Alert1.content = msg.failMsg;
                                                                            } else {
                                                                                Alert1.content = "添加章节失败";
                                                                            }
                                                                            Alert1.init();
                                                                            Alert1.show();
                                                                        }
                                                                    }
                                                                });
                                                            }
                                                        });
                                                        // 返回上一页
                                                        $(".cancelBtn").off("click").click(function() {
                                                            confirm1.content = "确定退出实验环境吗？";
                                                            confirm1.success = function () {
                                                                $("#ifMain",parent.document).attr("style","");
                                                                $(".virEnvirmentBox").remove();
                                                                self.testEditor("MarEditormd");
                                                                $("#MarEditormd textarea").val($("#LabEditormds textarea").val());
                                                                $("#MarEditormd .markdown-body").html('');
                                                                $("#layoutSub").remove();
                                                                $("#virtualBox").remove();
                                                                $(".sftpBox").remove();
                                                                $(".navSideBar").remove();
                                                                $(".modal").remove();
                                                                $(".packDown").remove();
                                                                $(".mbm").hide();

                                                                $("body").css("overflow","inherit");
                                                            };
                                                            confirm1.init();
                                                            confirm1.show();
                                                        });
                                                        $(".popup,.mb").hide();
                                                        $(".come,.imageBox").show();
                                                        $(".imagesBox").hide();
                                                        $(".types").removeClass("radioChecks");
                                                        $(".types").eq(0).addClass("radioChecks");
                                                        $("#oneConfig").val('2,2');
                                                        self.getImage(true);
                                                        // 配置
                                                        var str = '';
                                                        var str1 = '';
                                                        if(msg.data.masterImageId != undefined){
                                                            str += "<li data-value='1' data-url='"+ msg.data.masterDesktopUrl +"'  data-containerid="+ msg.data.masterContainerId +">主节点(当前)</li>";
                                                            str += "<li data-value='0' data-url='"+ msg.data.firstSlaveDesktopUrl +"'  data-containerid="+ msg.data.firstSlaveContainerId +">从节点1</li>";
                                                            str += "<li data-value='0' data-url='"+ msg.data.secondSlaveDesktopUrl +"'  data-containerid="+ msg.data.secondSlaveContainerId +">从节点2</li>";
                                                            $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='"+ msg.data.masterImageId +"' data-value='1' data-containerid="+ msg.data.masterContainerId  +" class=\"virMBox\" src="+msg.data.masterDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                                            $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='"+ msg.data.firstSlaveImageId +"'  data-value='0' data-containerid="+ msg.data.firstSlaveContainerId +" class=\"virMBox\" src="+msg.data.firstSlaveDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                                            $("#virtualBox").append("<iframe name='virMBoxes'  data-imageid='"+ msg.data.secondSlaveImageId +"' data-value='0' data-containerid="+ msg.data.secondSlaveContainerId +" class=\"virMBox\" src="+msg.data.secondSlaveDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                                            // $(".configBox>ul").html(str);
                                                            str1 += "<li type='1' class='nav mainVir' data-value='1' data-url='"+ msg.data.masterDesktopUrl +"'  data-containerid="+ msg.data.masterContainerId +">主节点</li>";
                                                            str1 += "<li type='2' class='nav subVir' data-value='0' data-url='"+ msg.data.firstSlaveDesktopUrl +"'  data-containerid="+ msg.data.firstSlaveContainerId +">从节点1</li>";
                                                            str1 += "<li type='2' class='nav thVir' data-value='0' data-url='"+ msg.data.secondSlaveDesktopUrl +"'  data-containerid="+ msg.data.secondSlaveContainerId +">从节点2</li>";
                                                            $(".virAfter").after(str1);
                                                            $(".saveImg").html("保存集群");
                                                            startWebSocket(msg.data.masterContainerId);
                                                            startWebSocket(msg.data.firstSlaveContainerId);
                                                            startWebSocket(msg.data.secondSlaveContainerId);
                                                        }else{
                                                            $(".saveImg").html("保存镜像");
                                                            // str += "<li data-value='1' data-url='"+ msg.data.desktopUrl +"'  data-containerid="+ msg.data.containerId +">单节点(当前)</li>";
                                                            $("#virtualBox").append("<iframe   name='virMBoxes' data-imageid='"+ msg.data.imageId +"' data-value='1' data-containerid="+ msg.data.containerId +" class=\"virMBox\" src="+msg.data.desktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                                            startWebSocket(msg.data.containerId);
                                                        }
                                                        $(".mainVir").css({"background":'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                        $(".mainVir").off("click").click(function () {
                                                            $(".nav").attr("style",'');
                                                            $(".nav").attr("data-value",'0');
                                                            $(this).css({"background":'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                            $(this).attr("data-value","1");
                                                            $(".virMBox").attr("data-value","0").hide();
                                                            $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                        });
                                                        $(".subVir").off("click").click(function () {
                                                            $(".nav").attr("style",'');
                                                            $(".nav").attr("data-value",'0');
                                                            $(this).css({"background":'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                            $(this).attr("data-value","1");
                                                            $(".virMBox").attr("data-value","0").hide();
                                                            $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                        });
                                                        $(".thVir").off("click").click(function () {
                                                            $(".nav").attr("style",'');
                                                            $(".nav").attr("data-value",'0');
                                                            $(this).css({"background":'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                            $(this).attr("data-value","1");
                                                            $(".virMBox").attr("data-value","0").hide();
                                                            $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                        });

                                                        // 获取sftp地址和端口
                                                        $.ajax({
                                                            type: "get",
                                                            url: "desktop/ftp",
                                                            data: {"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                                            async: true,
                                                            dataType: 'json',
                                                            contentType: 'application/json',
                                                            success: function (msg) {
                                                                if (msg.code == "200") {
                                                                    var arr = msg.data.ftp.split(":");
                                                                    $(".blueHtml").html(arr[0]);
                                                                    $(".blueHtml2").html(arr[1]);
                                                                }else{
                                                                    Alert1.content = msg.message;
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                    return false;
                                                                }
                                                            }
                                                        });
                                                        //重新选择镜像
                                                        $(".exchangeBtn").off("click").click(function () {
                                                            self.testEditor("LabEditormd");
                                                            $("#MarEditormd textarea").val($("#LabEditormds textarea").val());
                                                            self.allocateEvents(chapterId);
                                                        });
                                                        //保存镜像
                                                        $(".saveImg").off("click").click(function () {
                                                            if ($(".virMBox").length == 1) {
                                                                $("body").append(saveImage());
                                                                $(".radioc").off("click").click(function () {
                                                                    $(".radioc").removeClass("radioCheck2");
                                                                    $(this).addClass("radioCheck2");
                                                                    if ($(this).attr("data-value") == 2) {
                                                                        $(".inBox ").show();
                                                                    } else {
                                                                        $(".inBox ").hide();
                                                                    }
                                                                });
                                                                $(".imageClose").off("click").click(function () {
                                                                    $(".saveImgBg").remove();
                                                                    $(".saveImageBox").remove();
                                                                });
                                                                $(".saveImgTrue").off("click").click(function () {
                                                                    if ($("#imgName").val() == "" && $(".radioCheck2").attr("data-value") == 2) {
                                                                        Alert1.content = "请输入镜像名称";
                                                                        Alert1.init();
                                                                        Alert1.show();
                                                                    } else {
                                                                        if ($(".virMBox").length == 1) {
                                                                            if ($(".radioCheck2").attr("data-value") == 1) {
                                                                                loading1.show();
                                                                                var json = JSON.stringify({
                                                                                    "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                                                                    "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                                });
                                                                                $.ajax({
                                                                                    type: "post",
                                                                                    url: "image/cover",
                                                                                    dataType: 'json',
                                                                                    contentType: 'application/json',
                                                                                    data: json,
                                                                                    async: true,
                                                                                    success: function (msg) {
                                                                                        loading1.hide();
                                                                                        if (msg.code == 200) {
                                                                                            loading1.show();
                                                                                            var json = {"chapterIds": [chapterId]};
                                                                                            json.courseId = 0;
                                                                                            json.cluster = false;
                                                                                            json.imageId = msg.data.imageId;
                                                                                            $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                            json.flavor = flavor;
                                                                                            json = JSON.stringify(json);
                                                                                            $.ajax({
                                                                                                type: "post",
                                                                                                url: "image/allocate/confirm",
                                                                                                data: json,
                                                                                                dataType: "JSON",
                                                                                                contentType: 'application/json',
                                                                                                async: true,
                                                                                                success: function (msg) {
                                                                                                    loading1.hide();
                                                                                                    if (msg.code == 200) {
                                                                                                        Alert1.content = "保存镜像成功";
                                                                                                        $(".saveImgBg").remove();
                                                                                                        $(".saveImageBox").remove();
                                                                                                        var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                        $(".virMBox[data-value=1]").attr("src", url);
                                                                                                        Alert1.init();
                                                                                                        Alert1.show();
                                                                                                    } else {
                                                                                                        Alert1.content = msg.message;
                                                                                                        Alert1.init();
                                                                                                        Alert1.show();
                                                                                                        return false;
                                                                                                    }

                                                                                                },
                                                                                                error: function () {
                                                                                                    loading1.hide();
                                                                                                }
                                                                                            });
                                                                                        } else {
                                                                                            Alert1.content = msg.message;
                                                                                            Alert1.init();
                                                                                            Alert1.show();
                                                                                            return false;
                                                                                        }
                                                                                    }
                                                                                });
                                                                            } else {
                                                                                var json = JSON.stringify({
                                                                                    "imageName": $("#imgName").val(),
                                                                                    "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                                });
                                                                                loading1.show();
                                                                                $.ajax({
                                                                                    type: "post",
                                                                                    url: "image/create",
                                                                                    dataType: 'json',
                                                                                    contentType: 'application/json',
                                                                                    data: json,
                                                                                    async: true,
                                                                                    success: function (msg) {
                                                                                        loading1.hide();
                                                                                        if (msg.code == 200) {
                                                                                            loading1.show();
                                                                                            var json = {"chapterIds": [chapterId]};
                                                                                            json.courseId = 0;
                                                                                            json.cluster = false;
                                                                                            json.imageId = msg.data.imageId;
                                                                                            json.flavor = flavor;
                                                                                            $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                            json = JSON.stringify(json);
                                                                                            $.ajax({
                                                                                                type: "post",
                                                                                                url: "image/allocate/confirm",
                                                                                                data: json,
                                                                                                dataType: "JSON",
                                                                                                contentType: 'application/json',
                                                                                                async: true,
                                                                                                success: function (msg) {
                                                                                                    loading1.hide();
                                                                                                    if (msg.code == 200) {
                                                                                                        Alert1.content = "保存镜像成功";
                                                                                                        $(".saveImgBg").remove();
                                                                                                        $(".saveImageBox").remove();
                                                                                                        var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                        $(".virMBox[data-value=1]").attr("src", url);
                                                                                                        Alert1.init();
                                                                                                        Alert1.show();
                                                                                                    } else {
                                                                                                        Alert1.content = msg.message;
                                                                                                        Alert1.init();
                                                                                                        Alert1.show();
                                                                                                        return false;
                                                                                                    }

                                                                                                },
                                                                                                error: function () {
                                                                                                    loading1.hide();
                                                                                                }
                                                                                            });
                                                                                        } else {
                                                                                            Alert1.content = msg.message;
                                                                                            Alert1.init();
                                                                                            Alert1.show();
                                                                                            return false;
                                                                                        }
                                                                                    }
                                                                                });
                                                                            }
                                                                        }
                                                                    }
                                                                });
                                                            }else{
                                                                loading1.show();
                                                                var json = JSON.stringify({
                                                                    "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                                                    "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                });
                                                                $.ajax({
                                                                    type: "post",
                                                                    url: "image/cover",
                                                                    dataType: 'json',
                                                                    contentType: 'application/json',
                                                                    data: json,
                                                                    async: true,
                                                                    success: function (msg) {
                                                                        loading1.hide();
                                                                        if (msg.code == 200) {
                                                                            var json = {"chapterIds": [chapterId]};
                                                                            json.courseId = 0;
                                                                            json.cluster = false;
                                                                            json.imageId = msg.data.imageId;
                                                                            json.flavor = flavor;
                                                                            $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                            json = JSON.stringify(json);
                                                                            $(".saveImgBg").remove();
                                                                            $(".saveImageBox").remove();
                                                                            var json = JSON.stringify({
                                                                                "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                                                "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                                                "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                                            });
                                                                            $.ajax({
                                                                                type: "post",
                                                                                url: "cluster/create",
                                                                                dataType: 'json',
                                                                                contentType: 'application/json',
                                                                                data: json,
                                                                                async: true,
                                                                                success: function (msg) {
                                                                                    loading1.hide();
                                                                                    if (msg.code == 200) {
                                                                                        var json = {"chapterIds": [chapterId]};
                                                                                        json.courseId = 0;
                                                                                        json.cluster = true;
                                                                                        json.clusterId = msg.data.clusterId;
                                                                                        json.flavor = flavor;
                                                                                        json = JSON.stringify(json);
                                                                                        loading1.show();
                                                                                        $.ajax({
                                                                                            type: "post",
                                                                                            url: "image/allocate/confirm",
                                                                                            data: json,
                                                                                            dataType: "JSON",
                                                                                            contentType: 'application/json',
                                                                                            async: true,
                                                                                            success: function (msg) {
                                                                                                loading1.hide();
                                                                                                if (msg.code == 200) {
                                                                                                    Alert2.content = "保存集群成功";
                                                                                                    Alert2.init();
                                                                                                    Alert2.show();
                                                                                                    $(".saveImgBg").remove();
                                                                                                    $(".saveImageBox").remove();
                                                                                                    var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                    $(".virMBox[data-value=1]").attr("src", url);
                                                                                                } else {
                                                                                                    Alert1.content = msg.message;
                                                                                                    Alert1.init();
                                                                                                    Alert1.show();
                                                                                                    return false;
                                                                                                }

                                                                                            },
                                                                                            error: function () {
                                                                                                loading1.hide();
                                                                                            }
                                                                                        });
                                                                                    } else {
                                                                                        Alert1.content = msg.message;
                                                                                        Alert1.init();
                                                                                        Alert1.show();
                                                                                        return false;
                                                                                    }
                                                                                }
                                                                            });

                                                                        } else {
                                                                            confirm1.content = "不允许覆盖公有的镜像，确定创建新的镜像吗？";
                                                                            confirm1.success = function () {
                                                                                $("body").append(saveImage());
                                                                                $(".radioc").eq(0).removeClass("radioCheck2");
                                                                                $(".radioc").eq(1).addClass("radioCheck2");
                                                                                $(".inBox").show();
                                                                                $(".hideBox").hide();
                                                                                $(".radioc").off("click").click(function () {
                                                                                    $(".radioc").removeClass("radioCheck2");
                                                                                    $(this).addClass("radioCheck2");
                                                                                    if($(this).attr("data-value") == 2){
                                                                                        $(".inBox ").show();
                                                                                    }else{
                                                                                        $(".inBox ").hide();
                                                                                    }
                                                                                });
                                                                                $(".imageClose").off("click").click(function () {
                                                                                    $(".saveImgBg").remove();
                                                                                    $(".saveImageBox").remove();
                                                                                });
                                                                                $(".saveImgTrue").off("click").click(function () {
                                                                                    if ($("#imgName").val() == ""&&$(".radioCheck2").attr("data-value") == 2) {
                                                                                        Alert1.content = "请输入镜像名称";
                                                                                        Alert1.init();
                                                                                        Alert1.show();
                                                                                    } else {
                                                                                        var json = JSON.stringify({
                                                                                            "imageName": $("#imgName").val(),
                                                                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                                        });
                                                                                        loading1.show();
                                                                                        $.ajax({
                                                                                            type: "post",
                                                                                            url: "image/create",
                                                                                            dataType: 'json',
                                                                                            contentType: 'application/json',
                                                                                            data: json,
                                                                                            async: true,
                                                                                            success: function (msg) {
                                                                                                loading1.hide();
                                                                                                if (msg.code == 200) {
                                                                                                    loading1.hide();
                                                                                                    var json = {"chapterIds": [chapterId]};
                                                                                                    json.courseId = 0;
                                                                                                    json.cluster = false;
                                                                                                    json.imageId = msg.data.imageId;
                                                                                                    json.flavor = flavor;
                                                                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                                    json = JSON.stringify(json);
                                                                                                    var json = JSON.stringify({
                                                                                                        "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                                                                        "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                                                                        "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                                                                    });
                                                                                                    $.ajax({
                                                                                                        type: "post",
                                                                                                        url: "cluster/create",
                                                                                                        dataType: 'json',
                                                                                                        contentType: 'application/json',
                                                                                                        data: json,
                                                                                                        async: true,
                                                                                                        success: function (msg) {
                                                                                                            loading1.hide();
                                                                                                            if (msg.code == 200) {
                                                                                                                var json = {"chapterIds": [chapterId]};
                                                                                                                json.courseId = 0;
                                                                                                                json.cluster = true;
                                                                                                                json.clusterId = msg.data.clusterId;
                                                                                                                json.flavor = flavor;
                                                                                                                json = JSON.stringify(json);
                                                                                                                loading1.show();
                                                                                                                $.ajax({
                                                                                                                    type: "post",
                                                                                                                    url: "image/allocate/confirm",
                                                                                                                    data: json,
                                                                                                                    dataType: "JSON",
                                                                                                                    contentType: 'application/json',
                                                                                                                    async: true,
                                                                                                                    success: function (msg) {
                                                                                                                        loading1.hide();
                                                                                                                        if (msg.code == 200) {
                                                                                                                            Alert2.content = "保存集群成功";
                                                                                                                            Alert2.init();
                                                                                                                            Alert2.show();
                                                                                                                            $(".saveImgBg").remove();
                                                                                                                            $(".saveImageBox").remove();
                                                                                                                            var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                                            $(".virMBox[data-value=1]").attr("src", url);
                                                                                                                        } else {
                                                                                                                            Alert1.content = msg.message;
                                                                                                                            Alert1.init();
                                                                                                                            Alert1.show();
                                                                                                                            return false;
                                                                                                                        }

                                                                                                                    },
                                                                                                                    error: function () {
                                                                                                                        loading1.hide();
                                                                                                                    }
                                                                                                                });
                                                                                                            } else {
                                                                                                                Alert1.content = msg.message;
                                                                                                                Alert1.init();
                                                                                                                Alert1.show();
                                                                                                                return false;
                                                                                                            }
                                                                                                        }
                                                                                                    });
                                                                                                    $(".saveImgBg").remove();
                                                                                                    $(".saveImageBox").remove();
                                                                                                } else {
                                                                                                    Alert1.content = msg.message;
                                                                                                    Alert1.init();
                                                                                                    Alert1.show();
                                                                                                    return false;
                                                                                                }
                                                                                            }
                                                                                        });
                                                                                    }
                                                                                });
                                                                            };
                                                                            confirm1.init();
                                                                            confirm1.show();
                                                                        }
                                                                    }
                                                                });
                                                            }
                                                        });
                                                    } else {
                                                        Alert1.content = msg.message;
                                                        Alert1.init();
                                                        Alert1.show();
                                                        return false;
                                                    }

                                                },
                                                error:function () {
                                                    loading1.hide();
                                                }
                                            });
                                        }
                                    };
                                    confirm3.init();
                                    confirm3.show();
                                }
                            }else{
                                Alert3.content = "集群已损坏，集群包含已被删除的镜像，请重新配置。";
                                Alert3.success = function () {
                                    self.allocateEvents();
                                };
                                Alert3.init();
                                Alert3.show();

                            }

                        }else{
                            $(".popup,.mbm").show();
                            $(".come,.imageBox").show();

                            self.getImage();
                            $(".imagesBox").hide();
                            $(".type").removeClass("radioCheck");
                            $(".type").eq(0).addClass("radioCheck");
                            $(".types").removeClass("radioChecks");
                            $(".types").eq(0).addClass("radioChecks");
                            $(".type").off("click").click(function () {
                                $(this).addClass("radioCheck");
                                $(this).siblings("span").removeClass("radioCheck");
                                if($(this).attr("data-value") == 1){
                                    $(".come,.imageBox").show();
                                    $(".imagesBox").hide();
                                    $(".types").removeClass("radioChecks");
                                    $(".types").eq(0).addClass("radioChecks");
                                    $("#oneConfig").val('2,2');
                                    self.getImage(true);
                                }else{
                                    $(".come,.imageBox").hide();
                                    $(".imagesBox").show();
                                    $("#imagesFir").val('2,2');
                                    $("#imagesSec").val('2,2');
                                    $("#imagesThi").val('2,2');
                                    self.getAllImage();
                                }
                            });
                            $(".types").off("click").click(function () {
                                $(this).addClass("radioChecks");
                                $(this).siblings("span").removeClass("radioChecks");
                                if($(this).attr("data-value") == 1){
                                    self.getImage(true);
                                }else{
                                    self.getImage(false);
                                }
                            });
                            // 取消 x
                            $(".exportCancle").off("click").click(function () {
                                $(".popup,.mbm").hide();
                            });
                            $(".popup_img").off("click").click(function () {
                                $(".popup,.mbm").hide();
                            });
                            var clusterId;
                            var imageId;
                            // 提交
                            $(".exportBtn").off("click").click(function () {

                                var flag = true;
                                var json = {};
                                var url = '';
                                var type = 0;
                                var flavor='';
                                if($(".radioCheck").attr("data-value") == 1){
                                    // json.cluster = false;
                                    json.imageId = Number($("#oneImage").val());
                                    imageId = Number($("#oneImage").val());
                                    flavor = $("#oneConfig").val();
                                    url = "image/desktop";
                                    type = 1;
                                    if($("#oneImage").val() == null){
                                        Alert1.content = "请正确选择镜像";
                                        Alert1.init();
                                        Alert1.show();
                                        flag = false;
                                        return false;
                                    }
                                }else{
                                    // json.cluster = true;
                                    json.clusterId = Number($("#images").val());
                                    clusterId = Number($("#images").val());
                                    type = 2;
                                    flavor = $("#imagesFir").val()+","+$("#imagesSec").val()+","+$("#imagesThi").val();
                                    url = "cluster/desktop";
                                    if($("#images").val() == null){
                                        Alert1.content = "请正确选择集群";
                                        Alert1.init();
                                        Alert1.show();
                                        flag = false;
                                        return false;
                                    }
                                }
                                if(flag){
                                    loading1.show();
                                    $.ajax({
                                        type: "get",
                                        url: url,
                                        data: json,
                                        async: true,
                                        success: function(msg) {
                                            loading1.hide();
                                            if(msg.code == 200) {
                                                $(".virEnvirmentBox").remove();
                                                $("#layoutSub").remove();
                                                $("#virtualBox").remove();
                                                $(".sftpBox").remove();
                                                $(".navSideBar").remove();
                                                $(".modal").remove();
                                                $(".mbm").hide();
                                                $(".packDown").remove();
                                                $("#ifMain",parent.document).css({"position":"fixed","left":0,"top":0,"z-index":100});
                                                $("body").css("overflow","hidden");
                                                $(".virEnvirmentBox").remove();
                                                $("body").append('<div class="virEnvirmentBox" style="width: 100%;">' +
                                                    '<div class="titleBox">' +
                                                    '<div title="关闭" class="fr cancelBtn "><img src="pc/images/ico_shareClose.png" alt="关闭"></div>' +
                                                    '<div class="configBox">' +
                                                    '<ul>' +
                                                    '</ul>' +
                                                    '</div>' +
                                                    '</div>' +
                                                    '</div>' +
                                                    '<div class="navSideBar">' +
                                                    '<div data-value="0" class="closeSide">' +
                                                    '工具栏' +
                                                    '</div>' +
                                                    '<div class="toolsBox">' +
                                                    '<ul>' +
                                                    '<li class="relink">刷新</li>' +
                                                    '<li class="exchangeBtn">重选配置</li>' +
                                                    '<li class="saveImg">保存镜像</li>' +
                                                    '<li class="line"></li>' +
                                                    '<li class="sftp">SFTP工具</li>' +
                                                    '<li class="shearBoardBtn">剪切板</li>' +
                                                    '<li class="line virAfter"></li>' +
                                                    '</ul>' +
                                                    '</div>' +
                                                    '</div>'+
                                                    '<div class="sftpBox">' +
                                                    '<div class="sftpContentBox">' +
                                                    '<header>' +
                                                    'SFTP工具' +
                                                    '<img class="closeSftp" src="pc/images/ico_alertDel.png">' +
                                                    '</header>' +
                                                    '<div class="sftpContent">' +
                                                    '<div>' +
                                                    '<div>您可以使用SFTP工具上传、下载文件：</div>' +
                                                    '<div>SFTP访问的地址为 <i class="blue blueHtml"></i> 端口号为 <i class="blue blueHtml2"></i></div>' +
                                                    '<div>用户名： <i class="blue">root</i>&ensp;   密码： <i class="blue">root</i> </div>' +
                                                    '<hr>' +
                                                    '<h4>使用说明</h4>' +
                                                    '<div class="marg">1.请先下载SFTP工具&emsp;<a href="upload/pscp/psftp_64.exe" download> <img class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down64.png"> </a>&emsp;&emsp;&emsp;<a href="upload/pscp/psftp_32.exe" download> <img  class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down32.png"> </a></div>' +
                                                    '<div class="marg">2.使用登陆命令   <i class="grayBg">open username@host post</i></div>' +
                                                    '<div class="marg">说明：username为用户名 host 为主机地址，post为端口号。</div>' +
                                                    '<div class="marg">3.填写密码进入SFTP环境。</div>' +
                                                    '<div class="marg">4.上传命令   <i class="grayBg">put dir/something.txt  dir/another.txt  </i></div>' +
                                                    '<div class="marg">说明：dir/something.txt 为用户当前环境的地址+文件。dir/another.txt为虚拟环境的地址加文件。</div>' +
                                                    '<div class="marg">例如：命令 put D:/bigdata.sql  /home/bigdata.sql  则是把本地D盘的bigdata.sql 文件上传至虚拟环境home 目录。</div>' +
                                                    '<div class="marg">5.下载命令   <i class="grayBg">get  dir/something.txt   dir/another.txt </i></div>' +
                                                    '<div class="marg">说明：dir/something.txt 为虚拟环境的地址加文件。dir/another.txt用户当前环境的地址+文件。</div>' +
                                                    '<div class="marg">例如：命令 get /home/bigdata.sql  E:/bigdata.sql  则是把虚拟环境home 目录的bigdata.sql 文件下载至的本地E盘。</div>' +
                                                    '<div class="publicBtn fr closeSftp ">确定</div>' +
                                                    '</div>' +
                                                    '</div>' +
                                                    '</div>' +
                                                    '</div>'+
                                                    '<div id="virtualBox">' +
                                                    '</div>' +
                                                    '</div>');
                                                $("#virtualBox").height($(window).height() - 40);
                                                $(".contentSection").height($(window).height() -  40);
                                                $(".navSideBar").height($(window).height() -  40);
                                                $(window).resize(function() {
                                                    $("#virtualBox").height($(window).height() -  40);
                                                    $(".contentSection").height($(window).height() -  40);
                                                    $(".navSideBar").height($(window).height() -  40);
                                                });
                                                //编辑器
                                                $("body").append(testDocModels());
                                                var testEditors = editormd('LabEditormds', {
                                                    width     : '100%',
                                                    height    : 480,
                                                    toc       : true,
                                                    todoList  : true,
                                                    path      : 'pc/js/extends/lib/',
                                                    watch:false,
                                                    tex:true,
                                                    saveHTMLToTextarea : true,
                                                    imageUpload : true,
                                                    imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                                    imageUploadURL : "editormdPic/",
                                                    flowChart: true,
                                                    sequenceDiagram: true,
                                                    dialogLockScreen : false,
                                                    dialogShowMask : true,
                                                    dialogDraggable : false,
                                                    dialogMaskOpacity : 0.4,
                                                    dialogMaskBgColor : "#000",
                                                    toolbarIcons : function() {
                                                        return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                                    }
                                                });
                                                $("#LabEditormds textarea").val($("#MarEditormd textarea").val());
                                                // $(".closeLab").off("click").click(function () {
                                                //     $("#layoutSub").hide();
                                                //     $("body").append("<img src=\"pc/images/ico_labEditBtn.png\" class=\"packDown\" >");
                                                //     $(".packDown").off("click").click(function () {
                                                //         $("#layoutSub").show();
                                                //         $(this).remove();
                                                //     });
                                                // });
                                                $(".closeLab").off("click").click(function () {
                                                    $("#layoutSub").hide();
                                                    $("body").append("<img src=\"pc/images/ico_labEditBtn.png\" class=\"packDown\" >");
                                                    $(".packDown").off("click").click(function () {
                                                        $("#layoutSub").show();
                                                        var val =  $("#LabEditormds textarea").val();
                                                        testEditors = editormd('LabEditormds', {
                                                            width     : '100%',
                                                            height    : 480,
                                                            toc       : true,
                                                            todoList  : true,
                                                            path      : 'pc/js/extends/lib/',
                                                            watch:false,
                                                            saveHTMLToTextarea : true,
                                                            imageUpload : true,
                                                            tex:true,
                                                            imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                                            imageUploadURL : "editormdPic/",
                                                            flowChart: true,
                                                            sequenceDiagram: true,
                                                            dialogLockScreen : false,
                                                            dialogShowMask : true,
                                                            dialogDraggable : false,
                                                            dialogMaskOpacity : 0.4,
                                                            dialogMaskBgColor : "#000",
                                                            toolbarIcons : function() {
                                                                return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                                            }
                                                        });
                                                        $("#LabEditormds textarea").val(val);
                                                        $(this).remove();
                                                    });
                                                });
                                                var div1 = document.getElementById("layoutSub");
                                                var div2 = document.getElementById("labTitle");
                                                div2.onmousedown = function(e){
                                                    var e = e || window.event;
                                                    var x = e.clientX - div1.offsetLeft;
                                                    var y = e.clientY - div1.offsetTop;
                                                    if(e.preventDefault){
                                                        e.preventDefault();
                                                    }
                                                    else{
                                                        e.returnValue = false;
                                                    }
                                                    document.onmousemove = function(e){
                                                        var e = e || window.event;
                                                        if(e.preventDefault){
                                                            e.preventDefault();
                                                        }
                                                        else{
                                                            e.returnValue = false;
                                                        }
                                                        var wid = e.clientX - x ;
                                                        var hei = e.clientY - y ;
                                                        div1.style.left = wid + "px";
                                                        div1.style.top = hei + "px";
                                                    }
                                                };
                                                document.onmouseup = function(e){
                                                    var e = e || event;
                                                    document.onmousemove = null;
                                                    if(e.preventDefault){
                                                        e.preventDefault();
                                                    }
                                                    else{
                                                        e.returnValue = false;
                                                    }
                                                };
                                                // 剪切板
                                                $(".shearBoardBtn").off("click").click(function () {
                                                    var string = shearModel();
                                                    $("#clipboard-modal").remove();
                                                    $("body").append(string);
                                                    $(".shearClose").off("click").click(function () {
                                                        $(".modal").remove();
                                                    });
                                                    $(".clipboard-copy-btn").off("click").click(function () {
                                                        loading1.show();
                                                        var jsonStr = JSON.stringify({"content":$("#praseArea").val(),"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))});
                                                        $.ajax({
                                                            type: "post",
                                                            url: "desktop/clipboard",
                                                            data:jsonStr,
                                                            async: true,
                                                            dataType:'json',
                                                            contentType:'application/json',
                                                            success: function (msg) {
                                                                loading1.hide();
                                                                if (msg.code == "200") {
                                                                    $(".modal").remove();
                                                                    Alert1.content = "保存成功，请在实验环境中粘贴内容";
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                }else{
                                                                    Alert1.content = msg.message;
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                }
                                                            }
                                                        });
                                                    });
                                                });

                                                // SFTP
                                                $(".sftp").off("click").click(function () {
                                                    $(".sftpBox").show();
                                                    // 获取sftp地址和端口
                                                    $.ajax({
                                                        type: "get",
                                                        url: "desktop/ftp",
                                                        data: {"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                                        async: true,
                                                        dataType: 'json',
                                                        contentType: 'application/json',
                                                        success: function (msg) {
                                                            if (msg.code == "200") {
                                                                var arr = msg.data.ftp.split(":");
                                                                $(".blueHtml").html(arr[0]);
                                                                $(".blueHtml2").html(arr[1]);
                                                            }else{
                                                                Alert1.content = msg.message;
                                                                Alert1.init();
                                                                Alert1.show();
                                                                return false;
                                                            }
                                                        }
                                                    });
                                                });
                                                $(".closeSftp").off("click").click(function () {
                                                    $(".sftpBox").hide();
                                                });
                                                //刷新
                                                $(".relink").off("click").click(function () {
                                                    var url = $(".virMBox[data-value=1]").attr("src");
                                                    $(".virMBox[data-value=1]").attr("src",url);
                                                });
                                                // 工具栏
                                                $(".closeSide").off("click").click(function () {
                                                    if($(this).attr("data-value") == 0){
                                                        $(this).attr("data-value",1);
                                                        $(".navSideBar").animate({
                                                            "right":"-120px"
                                                        },300);
                                                    }else{
                                                        $(this).attr("data-value",0);
                                                        $(".navSideBar").animate({
                                                            "right":"0"
                                                        },300);
                                                    }
                                                });
                                                // 实验手册保存
                                                $(".saveLabs").off("click").click(function(){
                                                    var json = JSON.stringify({"htmlStr":$("#LabEditormds .editormd-preview").html(),"chapterId":chapterId,"testNameHtml":escape($("#LabEditormds textarea").val()),"courseMaterialNameHtml":'',"mark":2});
                                                    if($("#LabEditormds textarea").val()!=''&& $("#LabEditormds .markdown-body").html() == ''){
                                                        Alert1.content = "请点击预览查看编写效果";
                                                        Alert1.init();
                                                        Alert1.show();
                                                    }else{
                                                        $.ajax({
                                                            type: 'post',
                                                            url: 'addChapterMaterialOrTest',
                                                            async: true,
                                                            data: {
                                                                "jsonStr": json
                                                            },
                                                            success: function (msg) {
                                                                msg = JSON.parse(msg);
                                                                if (msg.result == "success") {
                                                                    Alert1.content = "保存成功";
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                    $(".checkBtn").attr("data-src",self.address+msg.filename);
                                                                    $(".checkBtn").siblings("b").attr("data-src",self.address+msg.filename);
                                                                } else {
                                                                    if (msg.failMsg != undefined) {
                                                                        Alert1.content = msg.failMsg;
                                                                    } else {
                                                                        Alert1.content = "添加章节失败";
                                                                    }
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                }
                                                            }
                                                        });
                                                    }
                                                });
                                                // 返回上一页
                                                $(".cancelBtn").off("click").click(function() {
                                                    confirm1.content = "确定退出实验环境吗？";
                                                    confirm1.success = function () {
                                                        $("#ifMain",parent.document).attr("style","");
                                                        $(".virEnvirmentBox").remove();
                                                        self.testEditor("MarEditormd");
                                                        $("#MarEditormd textarea").val($("#LabEditormds textarea").val());
                                                        $("#MarEditormd .markdown-body").html('');
                                                        $("#layoutSub").remove();
                                                        $("#virtualBox").remove();
                                                        $(".sftpBox").remove();
                                                        $(".navSideBar").remove();
                                                        $(".modal").remove();
                                                        $(".packDown").remove();
                                                        $(".mbm").hide();

                                                        $("body").css("overflow","inherit");
                                                    };
                                                    confirm1.init();
                                                    confirm1.show();
                                                });
                                                $(".popup,.mb").hide();
                                                $(".come,.imageBox").show();
                                                $(".imagesBox").hide();
                                                $(".types").removeClass("radioChecks");
                                                $(".types").eq(0).addClass("radioChecks");
                                                $("#oneConfig").val('2,2');
                                                self.getImage(true);
                                                // 配置
                                                var str = '';
                                                var str1 = '';
                                                if(msg.data.masterImageId != undefined){
                                                    str += "<li data-value='1' data-url='"+ msg.data.masterDesktopUrl +"'  data-containerid="+ msg.data.masterContainerId +">主节点(当前)</li>";
                                                    str += "<li data-value='0' data-url='"+ msg.data.firstSlaveDesktopUrl +"'  data-containerid="+ msg.data.firstSlaveContainerId +">从节点1</li>";
                                                    str += "<li data-value='0' data-url='"+ msg.data.secondSlaveDesktopUrl +"'  data-containerid="+ msg.data.secondSlaveContainerId +">从节点2</li>";
                                                    $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='"+ msg.data.masterImageId +"' data-value='1' data-containerid="+ msg.data.masterContainerId  +" class=\"virMBox\" src="+msg.data.masterDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                                    $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='"+ msg.data.firstSlaveImageId +"'  data-value='0' data-containerid="+ msg.data.firstSlaveContainerId +" class=\"virMBox\" src="+msg.data.firstSlaveDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                                    $("#virtualBox").append("<iframe name='virMBoxes'  data-imageid='"+ msg.data.secondSlaveImageId +"' data-value='0' data-containerid="+ msg.data.secondSlaveContainerId +" class=\"virMBox\" src="+msg.data.secondSlaveDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                                    // $(".configBox>ul").html(str);
                                                    str1 += "<li type='1' class='nav mainVir' data-value='1' data-url='"+ msg.data.masterDesktopUrl +"'  data-containerid="+ msg.data.masterContainerId +">主节点</li>";
                                                    str1 += "<li type='2' class='nav subVir' data-value='0' data-url='"+ msg.data.firstSlaveDesktopUrl +"'  data-containerid="+ msg.data.firstSlaveContainerId +">从节点1</li>";
                                                    str1 += "<li type='2' class='nav thVir' data-value='0' data-url='"+ msg.data.secondSlaveDesktopUrl +"'  data-containerid="+ msg.data.secondSlaveContainerId +">从节点2</li>";
                                                    $(".virAfter").after(str1);
                                                    $(".saveImg").html("保存集群");
                                                    startWebSocket(msg.data.masterContainerId);
                                                    startWebSocket(msg.data.firstSlaveContainerId);
                                                    startWebSocket(msg.data.secondSlaveContainerId);
                                                }else{
                                                    $(".saveImg").html("保存镜像");
                                                    // str += "<li data-value='1' data-url='"+ msg.data.desktopUrl +"'  data-containerid="+ msg.data.containerId +">单节点(当前)</li>";
                                                    $("#virtualBox").append("<iframe   name='virMBoxes' data-imageid='"+ msg.data.imageId +"' data-value='1' data-containerid="+ msg.data.containerId +" class=\"virMBox\" src="+msg.data.desktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                                    startWebSocket(msg.data.containerId);
                                                }
                                                $(".mainVir").css({"background":'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                $(".mainVir").off("click").click(function () {
                                                    $(".nav").attr("style",'');
                                                    $(".nav").attr("data-value",'0');
                                                    $(this).css({"background":'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                    $(this).attr("data-value","1");
                                                    $(".virMBox").attr("data-value","0").hide();
                                                    $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                });
                                                $(".subVir").off("click").click(function () {
                                                    $(".nav").attr("style",'');
                                                    $(".nav").attr("data-value",'0');
                                                    $(this).css({"background":'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                    $(this).attr("data-value","1");
                                                    $(".virMBox").attr("data-value","0").hide();
                                                    $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                });
                                                $(".thVir").off("click").click(function () {
                                                    $(".nav").attr("style",'');
                                                    $(".nav").attr("data-value",'0');
                                                    $(this).css({"background":'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                                    $(this).attr("data-value","1");
                                                    $(".virMBox").attr("data-value","0").hide();
                                                    $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                                });
                                                // 获取sftp地址和端口
                                                $.ajax({
                                                    type: "get",
                                                    url: "desktop/ftp",
                                                    data: {"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                                    async: true,
                                                    dataType: 'json',
                                                    contentType: 'application/json',
                                                    success: function (msg) {
                                                        if (msg.code == "200") {
                                                            var arr = msg.data.ftp.split(":");
                                                            $(".blueHtml").html(arr[0]);
                                                            $(".blueHtml2").html(arr[1]);
                                                        }else{
                                                            Alert1.content = msg.message;
                                                            Alert1.init();
                                                            Alert1.show();
                                                            return false;
                                                        }
                                                    }
                                                });

                                                //重新选择镜像
                                                $(".exchangeBtn").off("click").click(function () {
                                                    self.testEditor("LabEditormd");
                                                    $("#MarEditormd textarea").val($("#LabEditormds textarea").val());
                                                    self.allocateEvents(chapterId);
                                                });
                                                //保存镜像
                                                $(".saveImg").off("click").click(function () {
                                                    if ($(".virMBox").length == 1) {
                                                        $("body").append(saveImage());
                                                        $(".radioc").off("click").click(function () {
                                                            $(".radioc").removeClass("radioCheck2");
                                                            $(this).addClass("radioCheck2");
                                                            if ($(this).attr("data-value") == 2) {
                                                                $(".inBox ").show();
                                                            } else {
                                                                $(".inBox ").hide();
                                                            }
                                                        });
                                                        $(".imageClose").off("click").click(function () {
                                                            $(".saveImgBg").remove();
                                                            $(".saveImageBox").remove();
                                                        });
                                                        $(".saveImgTrue").off("click").click(function () {
                                                            if ($("#imgName").val() == "" && $(".radioCheck2").attr("data-value") == 2) {
                                                                Alert1.content = "请输入镜像名称";
                                                                Alert1.init();
                                                                Alert1.show();
                                                            } else {
                                                                if ($(".virMBox").length == 1) {
                                                                    if ($(".radioCheck2").attr("data-value") == 1) {
                                                                        loading1.show();
                                                                        var json = JSON.stringify({
                                                                            "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                        });
                                                                        $.ajax({
                                                                            type: "post",
                                                                            url: "image/cover",
                                                                            dataType: 'json',
                                                                            contentType: 'application/json',
                                                                            data: json,
                                                                            async: true,
                                                                            success: function (msg) {
                                                                                loading1.hide();
                                                                                if (msg.code == 200) {
                                                                                    loading1.show();
                                                                                    var json = {"chapterIds": [chapterId]};
                                                                                    json.courseId = 0;
                                                                                    json.cluster = false;
                                                                                    json.imageId = msg.data.imageId;
                                                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                    json.flavor = flavor;
                                                                                    json = JSON.stringify(json);
                                                                                    $.ajax({
                                                                                        type: "post",
                                                                                        url: "image/allocate/confirm",
                                                                                        data: json,
                                                                                        dataType: "JSON",
                                                                                        contentType: 'application/json',
                                                                                        async: true,
                                                                                        success: function (msg) {
                                                                                            loading1.hide();
                                                                                            if (msg.code == 200) {
                                                                                                Alert1.content = "保存镜像成功";
                                                                                                $(".saveImgBg").remove();
                                                                                                $(".saveImageBox").remove();
                                                                                                var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                $(".virMBox[data-value=1]").attr("src", url);
                                                                                                Alert1.init();
                                                                                                Alert1.show();
                                                                                            } else {
                                                                                                Alert1.content = msg.message;
                                                                                                Alert1.init();
                                                                                                Alert1.show();
                                                                                                return false;
                                                                                            }

                                                                                        },
                                                                                        error: function () {
                                                                                            loading1.hide();
                                                                                        }
                                                                                    });
                                                                                } else {
                                                                                    Alert1.content = msg.message;
                                                                                    Alert1.init();
                                                                                    Alert1.show();
                                                                                    return false;
                                                                                }
                                                                            }
                                                                        });
                                                                    }
                                                                } else {
                                                                    var json = JSON.stringify({
                                                                        "imageName": $("#imgName").val(),
                                                                        "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                    });
                                                                    loading1.show();
                                                                    $.ajax({
                                                                        type: "post",
                                                                        url: "image/create",
                                                                        dataType: 'json',
                                                                        contentType: 'application/json',
                                                                        data: json,
                                                                        async: true,
                                                                        success: function (msg) {
                                                                            loading1.hide();
                                                                            if (msg.code == 200) {
                                                                                loading1.show();
                                                                                var json = {"chapterIds": [chapterId]};
                                                                                json.courseId = 0;
                                                                                json.cluster = false;
                                                                                json.imageId = msg.data.imageId;
                                                                                json.flavor = flavor;
                                                                                $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                json = JSON.stringify(json);
                                                                                $.ajax({
                                                                                    type: "post",
                                                                                    url: "image/allocate/confirm",
                                                                                    data: json,
                                                                                    dataType: "JSON",
                                                                                    contentType: 'application/json',
                                                                                    async: true,
                                                                                    success: function (msg) {
                                                                                        loading1.hide();
                                                                                        if (msg.code == 200) {
                                                                                            Alert1.content = "保存镜像成功";
                                                                                            $(".saveImgBg").remove();
                                                                                            $(".saveImageBox").remove();
                                                                                            var url = $(".virMBox[data-value=1]").attr("src");
                                                                                            $(".virMBox[data-value=1]").attr("src", url);
                                                                                            Alert1.init();
                                                                                            Alert1.show();
                                                                                        } else {
                                                                                            Alert1.content = msg.message;
                                                                                            Alert1.init();
                                                                                            Alert1.show();
                                                                                            return false;
                                                                                        }

                                                                                    },
                                                                                    error: function () {
                                                                                        loading1.hide();
                                                                                    }
                                                                                });
                                                                            } else {
                                                                                Alert1.content = msg.message;
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                                return false;
                                                                            }
                                                                        }
                                                                    });
                                                                }
                                                            }
                                                        });
                                                    }else{
                                                        loading1.show();
                                                        var json = JSON.stringify({
                                                            "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                        });
                                                        $.ajax({
                                                            type: "post",
                                                            url: "image/cover",
                                                            dataType: 'json',
                                                            contentType: 'application/json',
                                                            data: json,
                                                            async: true,
                                                            success: function (msg) {
                                                                loading1.hide();
                                                                if (msg.code == 200) {
                                                                    var json = {"chapterIds": [chapterId]};
                                                                    json.courseId = 0;
                                                                    json.cluster = false;
                                                                    json.imageId = msg.data.imageId;
                                                                    json.flavor = flavor;
                                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                    json = JSON.stringify(json);
                                                                    $(".saveImgBg").remove();
                                                                    $(".saveImageBox").remove();
                                                                    var json = JSON.stringify({
                                                                        "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                                        "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                                        "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                                    });
                                                                    $.ajax({
                                                                        type: "post",
                                                                        url: "cluster/create",
                                                                        dataType: 'json',
                                                                        contentType: 'application/json',
                                                                        data: json,
                                                                        async: true,
                                                                        success: function (msg) {
                                                                            loading1.hide();
                                                                            if (msg.code == 200) {
                                                                                var json = {"chapterIds": [chapterId]};
                                                                                json.courseId = 0;
                                                                                json.cluster = true;
                                                                                json.clusterId = msg.data.clusterId;
                                                                                json.flavor = flavor;
                                                                                json = JSON.stringify(json);
                                                                                loading1.show();
                                                                                $.ajax({
                                                                                    type: "post",
                                                                                    url: "image/allocate/confirm",
                                                                                    data: json,
                                                                                    dataType: "JSON",
                                                                                    contentType: 'application/json',
                                                                                    async: true,
                                                                                    success: function (msg) {
                                                                                        loading1.hide();
                                                                                        if (msg.code == 200) {
                                                                                            Alert2.content = "保存集群成功";
                                                                                            Alert2.init();
                                                                                            Alert2.show();
                                                                                            $(".saveImgBg").remove();
                                                                                            $(".saveImageBox").remove();
                                                                                            var url = $(".virMBox[data-value=1]").attr("src");
                                                                                            $(".virMBox[data-value=1]").attr("src", url);
                                                                                        } else {
                                                                                            Alert1.content = msg.message;
                                                                                            Alert1.init();
                                                                                            Alert1.show();
                                                                                            return false;
                                                                                        }

                                                                                    },
                                                                                    error: function () {
                                                                                        loading1.hide();
                                                                                    }
                                                                                });
                                                                            } else {
                                                                                Alert1.content = msg.message;
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                                return false;
                                                                            }
                                                                        }
                                                                    });

                                                                } else {
                                                                    confirm1.content = "不允许覆盖公有的镜像，确定创建新的镜像吗？";
                                                                    confirm1.success = function () {
                                                                        $("body").append(saveImage());
                                                                        $(".radioc").eq(0).removeClass("radioCheck2");
                                                                        $(".radioc").eq(1).addClass("radioCheck2");
                                                                        $(".inBox").show();
                                                                        $(".hideBox").hide();
                                                                        $(".radioc").off("click").click(function () {
                                                                            $(".radioc").removeClass("radioCheck2");
                                                                            $(this).addClass("radioCheck2");
                                                                            if($(this).attr("data-value") == 2){
                                                                                $(".inBox ").show();
                                                                            }else{
                                                                                $(".inBox ").hide();
                                                                            }
                                                                        });
                                                                        $(".imageClose").off("click").click(function () {
                                                                            $(".saveImgBg").remove();
                                                                            $(".saveImageBox").remove();
                                                                        });
                                                                        $(".saveImgTrue").off("click").click(function () {
                                                                            if ($("#imgName").val() == ""&&$(".radioCheck2").attr("data-value") == 2) {
                                                                                Alert1.content = "请输入镜像名称";
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                            } else {
                                                                                var json = JSON.stringify({
                                                                                    "imageName": $("#imgName").val(),
                                                                                    "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                                });
                                                                                loading1.show();
                                                                                $.ajax({
                                                                                    type: "post",
                                                                                    url: "image/create",
                                                                                    dataType: 'json',
                                                                                    contentType: 'application/json',
                                                                                    data: json,
                                                                                    async: true,
                                                                                    success: function (msg) {
                                                                                        loading1.hide();
                                                                                        if (msg.code == 200) {
                                                                                            loading1.hide();
                                                                                            var json = {"chapterIds": [chapterId]};
                                                                                            json.courseId = 0;
                                                                                            json.cluster = false;
                                                                                            json.imageId = msg.data.imageId;
                                                                                            json.flavor = flavor;
                                                                                            $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                                            json = JSON.stringify(json);
                                                                                            var json = JSON.stringify({
                                                                                                "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                                                                "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                                                                "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                                                            });
                                                                                            $.ajax({
                                                                                                type: "post",
                                                                                                url: "cluster/create",
                                                                                                dataType: 'json',
                                                                                                contentType: 'application/json',
                                                                                                data: json,
                                                                                                async: true,
                                                                                                success: function (msg) {
                                                                                                    loading1.hide();
                                                                                                    if (msg.code == 200) {
                                                                                                        var json = {"chapterIds": [chapterId]};
                                                                                                        json.courseId = 0;
                                                                                                        json.cluster = true;
                                                                                                        json.clusterId = msg.data.clusterId;
                                                                                                        json.flavor = flavor;
                                                                                                        json = JSON.stringify(json);
                                                                                                        loading1.show();
                                                                                                        $.ajax({
                                                                                                            type: "post",
                                                                                                            url: "image/allocate/confirm",
                                                                                                            data: json,
                                                                                                            dataType: "JSON",
                                                                                                            contentType: 'application/json',
                                                                                                            async: true,
                                                                                                            success: function (msg) {
                                                                                                                loading1.hide();
                                                                                                                if (msg.code == 200) {
                                                                                                                    Alert2.content = "保存集群成功";
                                                                                                                    Alert2.init();
                                                                                                                    Alert2.show();
                                                                                                                    $(".saveImgBg").remove();
                                                                                                                    $(".saveImageBox").remove();
                                                                                                                    var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                                    $(".virMBox[data-value=1]").attr("src", url);
                                                                                                                } else {
                                                                                                                    Alert1.content = msg.message;
                                                                                                                    Alert1.init();
                                                                                                                    Alert1.show();
                                                                                                                    return false;
                                                                                                                }

                                                                                                            },
                                                                                                            error: function () {
                                                                                                                loading1.hide();
                                                                                                            }
                                                                                                        });
                                                                                                    } else {
                                                                                                        Alert1.content = msg.message;
                                                                                                        Alert1.init();
                                                                                                        Alert1.show();
                                                                                                        return false;
                                                                                                    }
                                                                                                }
                                                                                            });
                                                                                            $(".saveImgBg").remove();
                                                                                            $(".saveImageBox").remove();
                                                                                        } else {
                                                                                            Alert1.content = msg.message;
                                                                                            Alert1.init();
                                                                                            Alert1.show();
                                                                                            return false;
                                                                                        }
                                                                                    }
                                                                                });
                                                                            }
                                                                        });
                                                                    };
                                                                    confirm1.init();
                                                                    confirm1.show();
                                                                }
                                                            }
                                                        });
                                                    }
                                                });
                                            } else {
                                                Alert1.content = msg.message;
                                                Alert1.init();
                                                Alert1.show();
                                                return false;
                                            }

                                        },
                                        error:function () {
                                            loading1.hide();
                                        }
                                    });
                                }

                            });
                        }
                    }
                }
            });
        },
        allocateEvents:function (chapterId) {
            var self = this;
            $(".popup,.mbm").show();
            $(".come,.imageBox").show();

            self.getImage();
            $(".imagesBox").hide();
            $(".type").removeClass("radioCheck");
            $(".type").eq(0).addClass("radioCheck");
            $(".types").removeClass("radioChecks");
            $(".types").eq(0).addClass("radioChecks");
            $(".type").off("click").click(function () {
                $(this).addClass("radioCheck");
                $(this).siblings("span").removeClass("radioCheck");
                if($(this).attr("data-value") == 1){
                    $(".come,.imageBox").show();
                    $(".imagesBox").hide();
                    $(".types").removeClass("radioChecks");
                    $(".types").eq(0).addClass("radioChecks");
                    $("#oneConfig").val('2,2');
                    self.getImage(true);
                }else{
                    $(".come,.imageBox").hide();
                    $(".imagesBox").show();
                    $("#imagesFir").val('2,2');
                    $("#imagesSec").val('2,2');
                    $("#imagesThi").val('2,2');
                    self.getAllImage();
                }
            });
            $(".types").off("click").click(function () {
                $(this).addClass("radioChecks");
                $(this).siblings("span").removeClass("radioChecks");
                if($(this).attr("data-value") == 1){
                    self.getImage(true);
                }else{
                    self.getImage(false);
                }
            });
            // 取消 x
            $(".exportCancle").off("click").click(function () {
                $(".popup,.mbm").hide();
            });
            $(".popup_img").off("click").click(function () {
                $(".popup,.mbm").hide();
            });
            var clusterId;
            var imageId;
            // 提交
            $(".exportBtn").off("click").click(function () {

                var flag = true;
                var json = {};
                var url = '';
                var type = 0;
                var flavor='';
                if($(".radioCheck").attr("data-value") == 1){
                    // json.cluster = false;
                    json.imageId = Number($("#oneImage").val());
                    imageId = Number($("#oneImage").val());
                    flavor = $("#oneConfig").val();
                    url = "image/desktop";
                    type = 1;
                    if($("#oneImage").val() == null){
                        Alert1.content = "请正确选择镜像";
                        Alert1.init();
                        Alert1.show();
                        flag = false;
                        return false;
                    }
                }else{
                    // json.cluster = true;
                    json.clusterId = Number($("#images").val());
                    clusterId = Number($("#images").val());
                    type = 2;
                    flavor = $("#imagesFir").val()+","+$("#imagesSec").val()+","+$("#imagesThi").val();
                    url = "cluster/desktop";
                    if($("#images").val() == null){
                        Alert1.content = "请正确选择集群";
                        Alert1.init();
                        Alert1.show();
                        flag = false;
                        return false;
                    }
                }
                if(flag){
                    loading1.show();
                    $.ajax({
                        type: "get",
                        url: url,
                        data: json,
                        async: true,
                        success: function(msg) {
                            loading1.hide();
                            if(msg.code == 200) {
                                $(".virEnvirmentBox").remove();
                                $("#layoutSub").remove();
                                $("#virtualBox").remove();
                                $(".sftpBox").remove();
                                $(".navSideBar").remove();
                                $(".modal").remove();
                                $(".mbm").hide();
                                $(".packDown").remove();
                                $("#ifMain",parent.document).css({"position":"fixed","left":0,"top":0,"z-index":100});
                                $("body").css("overflow","hidden");
                                $(".virEnvirmentBox").remove();
                                $("body").append('<div class="virEnvirmentBox" style="width: 100%;">' +
                                    '<div class="titleBox">' +
                                    '<div title="关闭" class="fr cancelBtn "><img src="pc/images/ico_shareClose.png" alt="关闭"></div>' +
                                    '<div class="configBox">' +
                                    '<ul>' +
                                    '</ul>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '<div class="navSideBar">' +
                                    '<div data-value="0" class="closeSide">' +
                                    '工具栏' +
                                    '</div>' +
                                    '<div class="toolsBox">' +
                                    '<ul>' +
                                    '<li class="relink">刷新</li>' +
                                    '<li class="exchangeBtn">重选配置</li>' +
                                    '<li class="saveImg">保存镜像</li>' +
                                    '<li class="line"></li>' +
                                    '<li class="sftp">SFTP工具</li>' +
                                    '<li class="shearBoardBtn">剪切板</li>' +
                                    '<li class="line virAfter"></li>' +
                                    '</ul>' +
                                    '</div>' +
                                    '</div>'+
                                    '<div class="sftpBox">' +
                                    '<div class="sftpContentBox">' +
                                    '<header>' +
                                    'SFTP工具' +
                                    '<img class="closeSftp" src="pc/images/ico_alertDel.png">' +
                                    '</header>' +
                                    '<div class="sftpContent">' +
                                    '<div>' +
                                    '<div>您可以使用SFTP工具上传、下载文件：</div>' +
                                    '<div>SFTP访问的地址为 <i class="blue blueHtml"></i> 端口号为 <i class="blue blueHtml2"></i></div>' +
                                    '<div>用户名： <i class="blue">root</i>&ensp;   密码： <i class="blue">root</i> </div>' +
                                    '<hr>' +
                                    '<h4>使用说明</h4>' +
                                    '<div class="marg">1.请先下载SFTP工具&emsp;<a href="upload/pscp/psftp_64.exe" download> <img class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down64.png"> </a>&emsp;&emsp;&emsp;<a href="upload/pscp/psftp_32.exe" download> <img  class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down32.png"> </a></div>' +
                                    '<div class="marg">2.使用登陆命令   <i class="grayBg">open username@host post</i></div>' +
                                    '<div class="marg">说明：username为用户名 host 为主机地址，post为端口号。</div>' +
                                    '<div class="marg">3.填写密码进入SFTP环境。</div>' +
                                    '<div class="marg">4.上传命令   <i class="grayBg">put dir/something.txt  dir/another.txt  </i></div>' +
                                    '<div class="marg">说明：dir/something.txt 为用户当前环境的地址+文件。dir/another.txt为虚拟环境的地址加文件。</div>' +
                                    '<div class="marg">例如：命令 put D:/bigdata.sql  /home/bigdata.sql  则是把本地D盘的bigdata.sql 文件上传至虚拟环境home 目录。</div>' +
                                    '<div class="marg">5.下载命令   <i class="grayBg">get  dir/something.txt   dir/another.txt </i></div>' +
                                    '<div class="marg">说明：dir/something.txt 为虚拟环境的地址加文件。dir/another.txt用户当前环境的地址+文件。</div>' +
                                    '<div class="marg">例如：命令 get /home/bigdata.sql  E:/bigdata.sql  则是把虚拟环境home 目录的bigdata.sql 文件下载至的本地E盘。</div>' +
                                    '<div class="publicBtn fr closeSftp ">确定</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>'+
                                    '<div id="virtualBox">' +
                                    '</div>' +
                                    '</div>');
                                $("#virtualBox").height($(window).height() - 40);
                                $(".contentSection").height($(window).height() -  40);
                                $(".navSideBar").height($(window).height() -  40);
                                $(window).resize(function() {
                                    $("#virtualBox").height($(window).height() -  40);
                                    $(".contentSection").height($(window).height() -  40);
                                    $(".navSideBar").height($(window).height() -  40);
                                });
                                //编辑器
                                $("body").append(testDocModels());
                                var testEditors = editormd('LabEditormds', {
                                    width     : '100%',
                                    height    : 480,
                                    toc       : true,
                                    todoList  : true,
                                    path      : 'pc/js/extends/lib/',
                                    watch:false,
                                    tex:true,
                                    saveHTMLToTextarea : true,
                                    imageUpload : true,
                                    imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                    imageUploadURL : "editormdPic/",
                                    flowChart: true,
                                    sequenceDiagram: true,
                                    dialogLockScreen : false,
                                    dialogShowMask : true,
                                    dialogDraggable : false,
                                    dialogMaskOpacity : 0.4,
                                    dialogMaskBgColor : "#000",
                                    toolbarIcons : function() {
                                        return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                    }
                                });
                                $("#LabEditormds textarea").val($("#MarEditormd textarea").val());
                                $(".closeLab").off("click").click(function () {
                                    $("#layoutSub").hide();
                                    $("body").append("<img src=\"pc/images/ico_labEditBtn.png\" class=\"packDown\" >");
                                    $(".packDown").off("click").click(function () {
                                        $("#layoutSub").show();
                                        var val =  $("#LabEditormds textarea").val();
                                        testEditors = editormd('LabEditormds', {
                                            width     : '100%',
                                            height    : 480,
                                            toc       : true,
                                            todoList  : true,
                                            path      : 'pc/js/extends/lib/',
                                            watch:false,
                                            saveHTMLToTextarea : true,
                                            imageUpload : true,
                                            tex:true,
                                            imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                            imageUploadURL : "editormdPic/",
                                            flowChart: true,
                                            sequenceDiagram: true,
                                            dialogLockScreen : false,
                                            dialogShowMask : true,
                                            dialogDraggable : false,
                                            dialogMaskOpacity : 0.4,
                                            dialogMaskBgColor : "#000",
                                            toolbarIcons : function() {
                                                return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                            }
                                        });
                                        $("#LabEditormds textarea").val(val);
                                        $(this).remove();
                                    });
                                });
                                var div1 = document.getElementById("layoutSub");
                                var div2 = document.getElementById("labTitle");
                                div2.onmousedown = function(e){
                                    var e = e || window.event;
                                    var x = e.clientX - div1.offsetLeft;
                                    var y = e.clientY - div1.offsetTop;
                                    if(e.preventDefault){
                                        e.preventDefault();
                                    }
                                    else{
                                        e.returnValue = false;
                                    }
                                    document.onmousemove = function(e){
                                        var e = e || window.event;
                                        if(e.preventDefault){
                                            e.preventDefault();
                                        }
                                        else{
                                            e.returnValue = false;
                                        }
                                        var wid = e.clientX - x ;
                                        var hei = e.clientY - y ;
                                        div1.style.left = wid + "px";
                                        div1.style.top = hei + "px";
                                    }
                                };
                                document.onmouseup = function(e){
                                    var e = e || event;
                                    document.onmousemove = null;
                                    if(e.preventDefault){
                                        e.preventDefault();
                                    }
                                    else{
                                        e.returnValue = false;
                                    }
                                };
                                // 剪切板
                                $(".shearBoardBtn").off("click").click(function () {
                                    var string = shearModel();
                                    $("#clipboard-modal").remove();
                                    $("body").append(string);
                                    $(".shearClose").off("click").click(function () {
                                        $(".modal").remove();
                                    });
                                    $(".clipboard-copy-btn").off("click").click(function () {
                                        loading1.show();
                                        var jsonStr = JSON.stringify({"content":$("#praseArea").val(),"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))});
                                        $.ajax({
                                            type: "post",
                                            url: "desktop/clipboard",
                                            data:jsonStr,
                                            async: true,
                                            dataType:'json',
                                            contentType:'application/json',
                                            success: function (msg) {
                                                loading1.hide();
                                                if (msg.code == "200") {
                                                    $(".modal").remove();
                                                    Alert1.content = "保存成功，请在实验环境中粘贴内容";
                                                    Alert1.init();
                                                    Alert1.show();
                                                }else{
                                                    Alert1.content = msg.message;
                                                    Alert1.init();
                                                    Alert1.show();
                                                }
                                            }
                                        });
                                    });
                                });

                                // SFTP
                                $(".sftp").off("click").click(function () {
                                    $(".sftpBox").show();
                                    // 获取sftp地址和端口
                                    $.ajax({
                                        type: "get",
                                        url: "desktop/ftp",
                                        data: {"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                        async: true,
                                        dataType: 'json',
                                        contentType: 'application/json',
                                        success: function (msg) {
                                            if (msg.code == "200") {
                                                var arr = msg.data.ftp.split(":");
                                                $(".blueHtml").html(arr[0]);
                                                $(".blueHtml2").html(arr[1]);
                                            }else{
                                                Alert1.content = msg.message;
                                                Alert1.init();
                                                Alert1.show();
                                                return false;
                                            }
                                        }
                                    });
                                });
                                $(".closeSftp").off("click").click(function () {
                                    $(".sftpBox").hide();
                                });
                                //刷新
                                $(".relink").off("click").click(function () {
                                    var url = $(".virMBox[data-value=1]").attr("src");
                                    $(".virMBox[data-value=1]").attr("src",url);
                                });
                                // 工具栏
                                $(".closeSide").off("click").click(function () {
                                    if($(this).attr("data-value") == 0){
                                        $(this).attr("data-value",1);
                                        $(".navSideBar").animate({
                                            "right":"-120px"
                                        },300);
                                    }else{
                                        $(this).attr("data-value",0);
                                        $(".navSideBar").animate({
                                            "right":"0"
                                        },300);
                                    }
                                });
                                // 实验手册保存
                                $(".saveLabs").off("click").click(function(){
                                    var json = JSON.stringify({"htmlStr":$("#LabEditormds .editormd-preview").html(),"chapterId":chapterId,"testNameHtml":escape($("#LabEditormds textarea").val()),"courseMaterialNameHtml":'',"mark":2});
                                    if($("#LabEditormds textarea").val()!=''&& $("#LabEditormds .markdown-body").html() == ''){
                                        Alert1.content = "请点击预览查看编写效果";
                                        Alert1.init();
                                        Alert1.show();
                                    }else{
                                        $.ajax({
                                            type: 'post',
                                            url: 'addChapterMaterialOrTest',
                                            async: true,
                                            data: {
                                                "jsonStr": json
                                            },
                                            success: function (msg) {
                                                msg = JSON.parse(msg);
                                                if (msg.result == "success") {
                                                    Alert1.content = "保存成功";
                                                    Alert1.init();
                                                    Alert1.show();
                                                    $(".checkBtn").attr("data-src",self.address+msg.filename);
                                                    $(".checkBtn").siblings("b").attr("data-src",self.address+msg.filename);
                                                } else {
                                                    if (msg.failMsg != undefined) {
                                                        Alert1.content = msg.failMsg;
                                                    } else {
                                                        Alert1.content = "添加章节失败";
                                                    }
                                                    Alert1.init();
                                                    Alert1.show();
                                                }
                                            }
                                        });
                                    }
                                });
                                // 返回上一页
                                $(".cancelBtn").off("click").click(function() {
                                    confirm1.content = "确定退出实验环境吗？";
                                    confirm1.success = function () {
                                        $("#ifMain",parent.document).attr("style","");
                                        $(".virEnvirmentBox").remove();
                                        self.testEditor("MarEditormd");
                                        $("#MarEditormd textarea").val($("#LabEditormds textarea").val());
                                        $("#MarEditormd .markdown-body").html('');
                                        $("#layoutSub").remove();
                                        $("#virtualBox").remove();
                                        $(".sftpBox").remove();
                                        $(".navSideBar").remove();
                                        $(".modal").remove();
                                        $(".packDown").remove();
                                        $(".mbm").hide();

                                        $("body").css("overflow","inherit");
                                    };
                                    confirm1.init();
                                    confirm1.show();
                                });
                                $(".popup,.mb").hide();
                                $(".come,.imageBox").show();
                                $(".imagesBox").hide();
                                $(".types").removeClass("radioChecks");
                                $(".types").eq(0).addClass("radioChecks");
                                $("#oneConfig").val('2,2');
                                self.getImage(true);
                                // 配置
                                var str = '';
                                var str1 = '';
                                if(msg.data.masterImageId != undefined){
                                    str += "<li data-value='1' data-url='"+ msg.data.masterDesktopUrl +"'  data-containerid="+ msg.data.masterContainerId +">主节点(当前)</li>";
                                    str += "<li data-value='0' data-url='"+ msg.data.firstSlaveDesktopUrl +"'  data-containerid="+ msg.data.firstSlaveContainerId +">从节点1</li>";
                                    str += "<li data-value='0' data-url='"+ msg.data.secondSlaveDesktopUrl +"'  data-containerid="+ msg.data.secondSlaveContainerId +">从节点2</li>";
                                    $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='"+ msg.data.masterImageId +"' data-value='1' data-containerid="+ msg.data.masterContainerId  +" class=\"virMBox\" src="+msg.data.masterDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                    $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='"+ msg.data.firstSlaveImageId +"'  data-value='0' data-containerid="+ msg.data.firstSlaveContainerId +" class=\"virMBox\" src="+msg.data.firstSlaveDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                    $("#virtualBox").append("<iframe name='virMBoxes'  data-imageid='"+ msg.data.secondSlaveImageId +"' data-value='0' data-containerid="+ msg.data.secondSlaveContainerId +" class=\"virMBox\" src="+msg.data.secondSlaveDesktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                    // $(".configBox>ul").html(str);
                                    str1 += "<li type='1' class='nav mainVir' data-value='1' data-url='"+ msg.data.masterDesktopUrl +"'  data-containerid="+ msg.data.masterContainerId +">主节点</li>";
                                    str1 += "<li type='2' class='nav subVir' data-value='0' data-url='"+ msg.data.firstSlaveDesktopUrl +"'  data-containerid="+ msg.data.firstSlaveContainerId +">从节点1</li>";
                                    str1 += "<li type='2' class='nav thVir' data-value='0' data-url='"+ msg.data.secondSlaveDesktopUrl +"'  data-containerid="+ msg.data.secondSlaveContainerId +">从节点2</li>";
                                    $(".virAfter").after(str1);
                                    startWebSocket(msg.data.masterContainerId);
                                    startWebSocket(msg.data.firstSlaveContainerId);
                                    startWebSocket(msg.data.secondSlaveContainerId);
                                    $(".saveImg").html("保存集群");
                                }else{
                                    $(".saveImg").html("保存镜像");
                                    // str += "<li data-value='1' data-url='"+ msg.data.desktopUrl +"'  data-containerid="+ msg.data.containerId +">单节点(当前)</li>";
                                    $("#virtualBox").append("<iframe   name='virMBoxes' data-imageid='"+ msg.data.imageId +"' data-value='1' data-containerid="+ msg.data.containerId +" class=\"virMBox\" src="+msg.data.desktopUrl +"  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                    startWebSocket(msg.data.containerId);
                                }
                                $(".mainVir").css({"background":'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                $(".mainVir").off("click").click(function () {
                                    $(".nav").attr("style",'');
                                    $(".nav").attr("data-value",'0');
                                    $(this).css({"background":'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                    $(this).attr("data-value","1");
                                    $(".virMBox").attr("data-value","0").hide();
                                    $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                });
                                $(".subVir").off("click").click(function () {
                                    $(".nav").attr("style",'');
                                    $(".nav").attr("data-value",'0');
                                    $(this).css({"background":'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                    $(this).attr("data-value","1");
                                    $(".virMBox").attr("data-value","0").hide();
                                    $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                });
                                $(".thVir").off("click").click(function () {
                                    $(".nav").attr("style",'');
                                    $(".nav").attr("data-value",'0');
                                    $(this).css({"background":'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',"color":'#0fcc8c'});
                                    $(this).attr("data-value","1");
                                    $(".virMBox").attr("data-value","0").hide();
                                    $(".virMBox[data-containerid="+ $(this).attr("data-containerid") +"]").attr("data-value","1").show()
                                });
                                // 获取sftp地址和端口
                                $.ajax({
                                    type: "get",
                                    url: "desktop/ftp",
                                    data: {"containerId":Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                    async: true,
                                    dataType: 'json',
                                    contentType: 'application/json',
                                    success: function (msg) {
                                        if (msg.code == "200") {
                                            var arr = msg.data.ftp.split(":");
                                            $(".blueHtml").html(arr[0]);
                                            $(".blueHtml2").html(arr[1]);
                                        }else{
                                            Alert1.content = msg.message;
                                            Alert1.init();
                                            Alert1.show();
                                            return false;
                                        }
                                    }
                                });

                                //重新选择镜像
                                $(".exchangeBtn").off("click").click(function () {
                                    self.testEditor("LabEditormd");
                                    $("#MarEditormd textarea").val($("#LabEditormds textarea").val());
                                    self.allocateEvents(chapterId);
                                });
                                //保存镜像
                                $(".saveImg").off("click").click(function () {
                                    if ($(".virMBox").length == 1) {
                                        $("body").append(saveImage());
                                        $(".radioc").off("click").click(function () {
                                            $(".radioc").removeClass("radioCheck2");
                                            $(this).addClass("radioCheck2");
                                            if ($(this).attr("data-value") == 2) {
                                                $(".inBox ").show();
                                            } else {
                                                $(".inBox ").hide();
                                            }
                                        });
                                        $(".imageClose").off("click").click(function () {
                                            $(".saveImgBg").remove();
                                            $(".saveImageBox").remove();
                                        });
                                        $(".saveImgTrue").off("click").click(function () {
                                            if ($("#imgName").val() == "" && $(".radioCheck2").attr("data-value") == 2) {
                                                Alert1.content = "请输入镜像名称";
                                                Alert1.init();
                                                Alert1.show();
                                            } else {
                                                if ($(".virMBox").length == 1) {
                                                    if ($(".radioCheck2").attr("data-value") == 1) {
                                                        loading1.show();
                                                        var json = JSON.stringify({
                                                            "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                        });
                                                        $.ajax({
                                                            type: "post",
                                                            url: "image/cover",
                                                            dataType: 'json',
                                                            contentType: 'application/json',
                                                            data: json,
                                                            async: true,
                                                            success: function (msg) {
                                                                loading1.hide();
                                                                if (msg.code == 200) {
                                                                    loading1.show();
                                                                    var json = {"chapterIds": [chapterId]};
                                                                    json.courseId = 0;
                                                                    json.cluster = false;
                                                                    json.imageId = msg.data.imageId;
                                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                    json.flavor = flavor;
                                                                    json = JSON.stringify(json);
                                                                    $.ajax({
                                                                        type: "post",
                                                                        url: "image/allocate/confirm",
                                                                        data: json,
                                                                        dataType: "JSON",
                                                                        contentType: 'application/json',
                                                                        async: true,
                                                                        success: function (msg) {
                                                                            loading1.hide();
                                                                            if (msg.code == 200) {
                                                                                Alert1.content = "保存镜像成功";
                                                                                $(".saveImgBg").remove();
                                                                                $(".saveImageBox").remove();
                                                                                var url = $(".virMBox[data-value=1]").attr("src");
                                                                                $(".virMBox[data-value=1]").attr("src", url);
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                            } else {
                                                                                Alert1.content = msg.message;
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                                return false;
                                                                            }

                                                                        },
                                                                        error: function () {
                                                                            loading1.hide();
                                                                        }
                                                                    });
                                                                } else {
                                                                    Alert1.content = msg.message;
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                    return false;
                                                                }
                                                            }
                                                        });
                                                    } else {
                                                        var json = JSON.stringify({
                                                            "imageName": $("#imgName").val(),
                                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                        });
                                                        loading1.show();
                                                        $.ajax({
                                                            type: "post",
                                                            url: "image/create",
                                                            dataType: 'json',
                                                            contentType: 'application/json',
                                                            data: json,
                                                            async: true,
                                                            success: function (msg) {
                                                                loading1.hide();
                                                                if (msg.code == 200) {
                                                                    loading1.show();
                                                                    var json = {"chapterIds": [chapterId]};
                                                                    json.courseId = 0;
                                                                    json.cluster = false;
                                                                    json.imageId = msg.data.imageId;
                                                                    json.flavor = flavor;
                                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                    json = JSON.stringify(json);
                                                                    $.ajax({
                                                                        type: "post",
                                                                        url: "image/allocate/confirm",
                                                                        data: json,
                                                                        dataType: "JSON",
                                                                        contentType: 'application/json',
                                                                        async: true,
                                                                        success: function (msg) {
                                                                            loading1.hide();
                                                                            if (msg.code == 200) {
                                                                                Alert1.content = "保存镜像成功";
                                                                                $(".saveImgBg").remove();
                                                                                $(".saveImageBox").remove();
                                                                                var url = $(".virMBox[data-value=1]").attr("src");
                                                                                $(".virMBox[data-value=1]").attr("src", url);
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                            } else {
                                                                                Alert1.content = msg.message;
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                                return false;
                                                                            }

                                                                        },
                                                                        error: function () {
                                                                            loading1.hide();
                                                                        }
                                                                    });
                                                                } else {
                                                                    Alert1.content = msg.message;
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                    return false;
                                                                }
                                                            }
                                                        });
                                                    }
                                                }
                                            }
                                        });
                                    }else{
                                        loading1.show();
                                        var json = JSON.stringify({
                                            "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                        });
                                        $.ajax({
                                            type: "post",
                                            url: "image/cover",
                                            dataType: 'json',
                                            contentType: 'application/json',
                                            data: json,
                                            async: true,
                                            success: function (msg) {
                                                loading1.hide();
                                                if (msg.code == 200) {
                                                    var json = {"chapterIds": [chapterId]};
                                                    json.courseId = 0;
                                                    json.cluster = false;
                                                    json.imageId = msg.data.imageId;
                                                    json.flavor = flavor;
                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                    json = JSON.stringify(json);
                                                    $(".saveImgBg").remove();
                                                    $(".saveImageBox").remove();
                                                    var json = JSON.stringify({
                                                        "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                        "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                        "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                    });
                                                    $.ajax({
                                                        type: "post",
                                                        url: "cluster/create",
                                                        dataType: 'json',
                                                        contentType: 'application/json',
                                                        data: json,
                                                        async: true,
                                                        success: function (msg) {
                                                            loading1.hide();
                                                            if (msg.code == 200) {
                                                                var json = {"chapterIds": [chapterId]};
                                                                json.courseId = 0;
                                                                json.cluster = true;
                                                                json.clusterId = msg.data.clusterId;
                                                                json.flavor = flavor;
                                                                json = JSON.stringify(json);
                                                                loading1.show();
                                                                $.ajax({
                                                                    type: "post",
                                                                    url: "image/allocate/confirm",
                                                                    data: json,
                                                                    dataType: "JSON",
                                                                    contentType: 'application/json',
                                                                    async: true,
                                                                    success: function (msg) {
                                                                        loading1.hide();
                                                                        if (msg.code == 200) {
                                                                            Alert2.content = "保存集群成功";
                                                                            Alert2.init();
                                                                            Alert2.show();
                                                                            $(".saveImgBg").remove();
                                                                            $(".saveImageBox").remove();
                                                                            var url = $(".virMBox[data-value=1]").attr("src");
                                                                            $(".virMBox[data-value=1]").attr("src", url);
                                                                        } else {
                                                                            Alert1.content = msg.message;
                                                                            Alert1.init();
                                                                            Alert1.show();
                                                                            return false;
                                                                        }

                                                                    },
                                                                    error: function () {
                                                                        loading1.hide();
                                                                    }
                                                                });
                                                            } else {
                                                                Alert1.content = msg.message;
                                                                Alert1.init();
                                                                Alert1.show();
                                                                return false;
                                                            }
                                                        }
                                                    });

                                                } else {
                                                    confirm1.content = "不允许覆盖公有的镜像，确定创建新的镜像吗？";
                                                    confirm1.success = function () {
                                                        $("body").append(saveImage());
                                                        $(".radioc").eq(0).removeClass("radioCheck2");
                                                        $(".radioc").eq(1).addClass("radioCheck2");
                                                        $(".inBox").show();
                                                        $(".hideBox").hide();
                                                        $(".radioc").off("click").click(function () {
                                                            $(".radioc").removeClass("radioCheck2");
                                                            $(this).addClass("radioCheck2");
                                                            if($(this).attr("data-value") == 2){
                                                                $(".inBox ").show();
                                                            }else{
                                                                $(".inBox ").hide();
                                                            }
                                                        });
                                                        $(".imageClose").off("click").click(function () {
                                                            $(".saveImgBg").remove();
                                                            $(".saveImageBox").remove();
                                                        });
                                                        $(".saveImgTrue").off("click").click(function () {
                                                            if ($("#imgName").val() == ""&&$(".radioCheck2").attr("data-value") == 2) {
                                                                Alert1.content = "请输入镜像名称";
                                                                Alert1.init();
                                                                Alert1.show();
                                                            } else {
                                                                var json = JSON.stringify({
                                                                    "imageName": $("#imgName").val(),
                                                                    "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                });
                                                                loading1.show();
                                                                $.ajax({
                                                                    type: "post",
                                                                    url: "image/create",
                                                                    dataType: 'json',
                                                                    contentType: 'application/json',
                                                                    data: json,
                                                                    async: true,
                                                                    success: function (msg) {
                                                                        loading1.hide();
                                                                        if (msg.code == 200) {
                                                                            loading1.hide();
                                                                            var json = {"chapterIds": [chapterId]};
                                                                            json.courseId = 0;
                                                                            json.cluster = false;
                                                                            json.imageId = msg.data.imageId;
                                                                            json.flavor = flavor;
                                                                            $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                            json = JSON.stringify(json);
                                                                            var json = JSON.stringify({
                                                                                "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                                                "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                                                "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                                            });
                                                                            $.ajax({
                                                                                type: "post",
                                                                                url: "cluster/create",
                                                                                dataType: 'json',
                                                                                contentType: 'application/json',
                                                                                data: json,
                                                                                async: true,
                                                                                success: function (msg) {
                                                                                    loading1.hide();
                                                                                    if (msg.code == 200) {
                                                                                        var json = {"chapterIds": [chapterId]};
                                                                                        json.courseId = 0;
                                                                                        json.cluster = true;
                                                                                        json.clusterId = msg.data.clusterId;
                                                                                        json.flavor = flavor;
                                                                                        json = JSON.stringify(json);
                                                                                        loading1.show();
                                                                                        $.ajax({
                                                                                            type: "post",
                                                                                            url: "image/allocate/confirm",
                                                                                            data: json,
                                                                                            dataType: "JSON",
                                                                                            contentType: 'application/json',
                                                                                            async: true,
                                                                                            success: function (msg) {
                                                                                                loading1.hide();
                                                                                                if (msg.code == 200) {
                                                                                                    Alert2.content = "保存集群成功";
                                                                                                    Alert2.init();
                                                                                                    Alert2.show();
                                                                                                    $(".saveImgBg").remove();
                                                                                                    $(".saveImageBox").remove();
                                                                                                    var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                    $(".virMBox[data-value=1]").attr("src", url);
                                                                                                } else {
                                                                                                    Alert1.content = msg.message;
                                                                                                    Alert1.init();
                                                                                                    Alert1.show();
                                                                                                    return false;
                                                                                                }

                                                                                            },
                                                                                            error: function () {
                                                                                                loading1.hide();
                                                                                            }
                                                                                        });
                                                                                    } else {
                                                                                        Alert1.content = msg.message;
                                                                                        Alert1.init();
                                                                                        Alert1.show();
                                                                                        return false;
                                                                                    }
                                                                                }
                                                                            });
                                                                            $(".saveImgBg").remove();
                                                                            $(".saveImageBox").remove();
                                                                        } else {
                                                                            Alert1.content = msg.message;
                                                                            Alert1.init();
                                                                            Alert1.show();
                                                                            return false;
                                                                        }
                                                                    }
                                                                });
                                                            }
                                                        });
                                                    };
                                                    confirm1.init();
                                                    confirm1.show();
                                                }
                                            }
                                        });
                                    }
                                });
                            } else {
                                Alert1.content = msg.message;
                                Alert1.init();
                                Alert1.show();
                                return false;
                            }

                        },
                        error:function () {
                            loading1.hide();
                        }
                    });
                }

            });
        },
        getData:function(){
//			获取头部信息，章节列表
            var self = this;
            var jsonStr = JSON.stringify({
                "courseId":result.paramData.courseId
            });
            $.ajax({
                type:"post",
                url:"skipCourseStudyDetail",
                async:true,
                data:{
                    "jsonStr":jsonStr
                },
                success:function(msg){
                    msg = JSON.parse(msg);
                    $iconfont.html(msg.courseDetail.courseTitle);
                    $iconfont.css({"color":msg.courseDetail.courseColer,"border-color":msg.courseDetail.courseColer});
                    $iconfont.siblings("p").html(msg.courseDetail.courseName);
                    $iconfont.siblings("p").attr("title",msg.courseDetail.courseName);
                    var str = "";
                    var downIsOk = msg.donwload_juirs;
                    if(msg.chapterList.length!=0){
                        $.map(msg.chapterList, function(opt) {
                            str += chapterListModel(opt,msg.url);
                        });
                        $chapterList.append(str);
                        // if(result.roleId == 2){
                        //     $(".download").remove();
                        // }
                        if(downIsOk == 1){
                            $(".download").remove();
                        }
                        for(var j =0;j<$(".oneChapter").length;j++){
                            for(var i=0;i<$(".oneChapter").eq(j).next().children("li").length;i++){
                                $(".oneChapter").eq(j).next().children("li").eq(i).append("<i>"+  $(".oneChapter").eq(j).attr("data-chapternum")+"-"+ (i+1) +"."+"</i>");
                            }
                        }
                        $(".chapterNameBox").hover(function () {
                            $(this).children("b").show();
                        },function () {
                            $(this).children("b").hide();
                        });
                        // 编辑章节
                        $(".editChapter").off("click").click(function () {
                            var type = $(this).attr("data-type");
                            var chapterId = Number($(this).attr("data-chapterid"));
                            var chapterNum = Number($(this).attr("data-chapternum"));
                            var url = $(this).attr("data-src");
                            $(".editSection").remove();
                            var json = JSON.stringify({"chapterId":chapterId,"courseId":Number(result.paramData.courseId),"chapterNum":chapterNum});
                            self.editChapterEvent(json,type,url,chapterId);
                        });
                        //修改章节名称
                        $(".editChapterName").off("click").click(function () {
                            var that = $(this);
                            confirm1.contenthead = "修改章节名称";
                            confirm1.content = '<div class="inputRight"><label for="courseName">章节名称:&ensp;</label>' +
                                '<input autocomplete="off" maxlength="20" type="text"  id="editName" value="'+ that.attr("data-name") +'" class="publicText">' +
                                '</div>';
                            confirm1.success = function () {
                                if($("#editName").val() === ''){
                                    Alert1.content = "请输入章节名称";
                                    Alert1.success = function () {
                                        confirm1.show();
                                    };
                                    Alert1.init();
                                    Alert1.show();
                                    return false;
                                }else{
                                    var json = JSON.stringify({"chapterId":Number(that.attr("data-chapterid")),"addTestMark":Number(that.attr("data-addtestmark")),"chapterName":$("#editName").val()});
                                    $.ajax({
                                        type: 'post',
                                        url: 'saveChapterTop',
                                        async: true,
                                        data: {
                                            "jsonStr": json
                                        },
                                        success: function (msg) {
                                            msg = JSON.parse(msg);
                                            if (msg.result == "success") {
                                                Alert1.content = '保存成功';
                                                Alert1.init();
                                                Alert1.show();
                                                that.attr("data-name",$("#editName").val());
                                                that.siblings("span").html(that.attr("data-num")+"-"+$("#editName").val());
                                                that.siblings("span").attr("data-name",that.attr("data-num")+"-"+$("#editName").val());
                                            }else{
                                                Alert5.content = msg.failMsg;
                                                $("#editName").parent().parent().parent().parent().show();
                                                $("#editName").parent().parent().parent().parent().next().show();
                                                Alert5.init();
                                                Alert5.show();
                                            }
                                        }
                                    });
                                }

                            };
                            confirm1.init();
                            confirm1.show();
                        });
                    }
                    self.selectEvent();
                    self.btnFun(msg.url);
                    self.authority(msg.roleId);
                }
            });

        },
        testEditor:function(id){
            testEditor = editormd(id, {
                width     : '98%',
                height    : 680,
                toc       : true,
                todoList  : true,
                path      : 'pc/js/extends/lib/',
                watch:false,
                emoji: true,
                tex:true,
                saveHTMLToTextarea : true,
                imageUpload : true,
                imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                imageUploadURL : "editormdPic/",
                flowChart: true,
                sequenceDiagram: true,
                dialogLockScreen : false,
                dialogShowMask : true,
                dialogDraggable : false,
                dialogMaskOpacity : 0.4,
                dialogMaskBgColor : "#000",
                toolbarIcons : function() {
                    return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                }
            })
        },
        fileEvent:function (chapterId,infoStr,url,stuUrl) {
            $(".file").off("change").change(function() {
                var formData = new FormData($(this).parent()[0]);
                if($(this).val() != ""){
                    var type = $(this).val().substring($(this).val().lastIndexOf(".")).toLowerCase(); // 取文件格式后缀名
                    var flag = true;
                    if($(this).attr("data-type") != undefined){
                        if(type != $(this).attr("data-type")) {
                            $(this).val("");
                            Alert1.content = "请上传正确格式文件，谢谢合作！";
                            Alert1.init();
                            Alert1.show();
                            flag = false;
                        }
                    }
                    if($(this).attr("data-size") != undefined){
                        if($(this)[0].files[0].size > $(this).attr("data-size")*1024*1024) {
                            $(this).val("");
                            Alert1.content = "上传文件最大为"+ $(this).attr("data-size") +"M，谢谢合作！";
                            Alert1.init();
                            Alert1.show();
                            flag = false;
                        }
                    }
                    var that = $(this);
                    if(flag){
                        loading1.show();
                        if(that.attr("data-url") == 'addChapterHomework' || that.attr("data-url") == 'addChapterExpreexcel'){
                            formData.append("mark",2);
                        }
                        $.ajax({
                            url: that.attr("data-url"),
                            type: 'post',
                            data: formData,
                            async: true,
                            cache: false,
                            contentType: false,
                            processData: false,
                            success: function(msg) {
                                loading1.hide();
                                msg = JSON.parse(msg);
                                if(msg.result == "success") {
                                    Alert1.content = "上传成功";
                                    Alert1.init();
                                    Alert1.show();
                                    $(".downHtml").attr("href",url+msg.filename);
                                    $(".checkBtn").attr("data-src",url+msg.filename);
                                    $(".checkBtn").siblings("b").attr("data-src",url+msg.filename);
                                    var str = "";
                                    if(that.attr("name") == "courseware"){
                                        $(".checkBtn").attr("data-src",url+msg.coursewareNameHtml);
                                        str = "delCourseware";
                                    }else if(that.attr("name") == "homeworkexcel"){
                                        str = "delHomework";
                                    }else if(that.attr("name") == "video"){
                                        str = "delVideo";
                                    }else if(that.attr("name") == "expreexcel"){
                                        str = "delExprement";
                                    }else{
                                        str = "delPackageFile";
                                    }
                                    $(".tip").prev().remove();
                                    $(".tip").prev().remove();
                                    $(".tip").before("<span>"+ that.val().substring(that.val().lastIndexOf("\\")+1)+"</span><img src='pc/images/ico_uploadRemove.png' data-text='"+ str +"' class='delBtn'>");
                                    that.val("");
                                    if(msg.expreList!=undefined){
                                        var str = escape(labModel(msg.expreList[0]));
                                        var json = JSON.stringify({"homeOrExpreMark":2,"chapterId":msg.charpterId,"homewokHtmlStr":"","expreHtmlStr":str,"homworkPaperDetail":"","exprementPaperDetail":msg.expreList[0].exprelibrarySource});
                                        $.ajax({
                                            type: 'post',
                                            url: 'addHtmlChapter',
                                            async: true,
                                            data: {
                                                "jsonStr": json
                                            },
                                            success: function (msg) {
                                                msg = JSON.parse(msg);
                                                if (msg.result != "success") {
                                                    Alert1.content = msg.failMsg;
                                                    Alert1.init();
                                                    Alert1.show();
                                                }
                                            }
                                        });
                                    }
                                    if(msg.taskOptionList != undefined || msg.taskManyOptionList != undefined ||msg.taskBlankList != undefined ||msg.taskJudgeList != undefined ||msg.taskAnswerList != undefined ){
                                        var strings = "";
                                        var num = 0;
                                        count = 0;
                                        var str = "";
                                        var str1 = "";
                                        var str2 = "";
                                        var str3 = "";
                                        var str4 = "";
                                        if(msg.taskOptionList.length!=0){
                                            // num++;
                                            str = choseModel(num,msg.taskOptionList);
                                            num += msg.taskOptionList.length;
                                        }
                                        if(msg.taskManyOptionList.length!=0){

                                            str4 = muchModel(num,msg.taskManyOptionList);
                                            num +=msg.taskManyOptionList.length;
                                        }
                                        if(msg.taskJudgeList.length!=0){
                                            // num++;
                                            str1 = checkModel(num,msg.taskJudgeList);
                                            num +=msg.taskJudgeList.length;
                                        }
                                        if(msg.taskBlankList.length!=0){
                                            // num++;
                                            str2 = fillModel(num,msg.taskBlankList);
                                            num +=msg.taskBlankList.length;
                                        }
                                        if(msg.taskAnswerList.length!=0){
                                            // num++;
                                            str3 = shortModel(num,msg.taskAnswerList);
                                            num +=msg.taskBlankList.length;
                                        }
                                        strings = "<div class='homeShowBox'>"+str+str4+str1+str2+str3+"</div>";
                                        var json = JSON.stringify({"homeOrExpreMark":1,"chapterId":msg.charpterId,"homewokHtmlStr":escape(strings.replace(/\(\+\)/g,"(&emsp;&emsp;)")),"expreHtmlStr":"","homworkPaperDetail":JSON.stringify(msg),"exprementPaperDetail":"","cssStr":'@charset "utf-8";button:focus,input,input:focus,select,textarea:focus{outline:0}body,dd,dl,dt,form,h1,h2,h3,h4,h5,h6,input,li,ol,p,textarea,ul{margin:0;padding:0}select::-ms-expand{display:none;}select{border:1px solid #dcd9d9;appearance:none;-moz-appearance:none;-webkit-appearance:none;background:url(../../images/select.gif) right 10px center no-repeat #FFF}body,html{width:100%}label{font-size:16px!important;}.popup_content{font-size:16px!important;}body{font-size:16px;line-height:1.7;font-family:"Microsoft YaHei",simhei;color:#333;background-color:#ffffff;}input,select,textarea{color:#333;outline:none;}input{border:1px solid #dfdfdf;}input[type=checkbox]{-webkit-appearance:none;appearance:none;width:14px;vertical-align:middle;height:14px;margin:0;cursor:pointer;background:#fff;border:1px solid #a0a0a0;-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:3px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:relative;}input[type=checkbox]:active,input[type=radio]:active{border-color:#a0a0a0;background:#fff;}input[type=checkbox]:hover{border-color:#a0a0a0;-webkit-box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);}input[type=checkbox]:checked,input[type=radio]:checked{background:#fff;}input[type=checkbox]:checked::after{content:url(../../images/ico_ok.png);display:block;position:absolute;top:-2px;left:2px;}input[type=checkbox]:focus{outline:none;border-color:#a0a0a0;}input[type=text]:focus{outline:none;}input:-webkit-autofill{-webkit-box-shadow:0 0 0px 1000px white inset;}ul,ol{list-style:none;}a{text-decoration:none;color:#333;font-size:16px}a:visited{color:#333;}a:hover,a:active,a:focus{color:#333;}em,i{font-style:normal}b,strong{font-weight:normal;}.fl{float:left}.fr{float:right}.clear{clear:both;height:0;overflow:hidden;}img{font-size:0;display:block;overflow:hidden;}table{table-layout:fixed;}td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}::-webkit-input-placeholder{color:#999999;}:-moz-placeholder{color:#999999;}::-moz-placeholder{color:#999999;}:-ms-input-placeholder{color:#999999;}.masking,.mb{position:fixed;width:100%;height:100%;z-index:0;background:rgba(0,0,0,0.7);top:0;left:0;display:none;}.choseOne{padding:0 15px;margin-bottom:10px;}.trueAnswer{margin-left:16px;color:#c80211;}.shortAnswer{width:50%;height:130px;resize:none;font-size:16px;padding:20px;display:none;}.answerInt{width:50px;height:20px;border:none;padding:0 5px;text-align:center;font-size:16px;min-width:50px;word-break:break-all;}.choseOne .shortAnswer{border:1px solid #cdcdcd;height:100px;width:500px;margin:20px 0;text-align:left;padding:10px;display:none;}.getScoreInt{height:20px;width:50px;text-align:center;}.getDisplay{color:#c80211;margin-left:46px;display:none;}.saveMar,.saveHome{display:none}#contentBox{background:#fff;}#contentBox>div{margin:0;}textarea{display:none!important;}',
                                        });
                                        $.ajax({
                                            type: 'post',
                                            url: 'addHtmlChapter',
                                            async: true,
                                            data: {
                                                "jsonStr": json
                                            },
                                            success: function (result) {
                                                var results = JSON.parse(result);
                                                if (results.result != "success") {
                                                    Alert1.content = results.failMsg;
                                                    Alert1.init();
                                                    Alert1.show();
                                                }else{
                                                    $(".downHtml").attr("href",stuUrl+results.modalName);
                                                    $(".checkBtn").attr("data-src",stuUrl+results.filename);
                                                    $(".checkBtn").siblings("b").attr("data-src",stuUrl+msg.filename);
                                                }
                                            }
                                        });

                                    }
                                    //下载
                                    $(".downHtml").off("click").click(function () {
                                        if($(this).attr("href").indexOf(".rar") != -1||$(this).attr("href").indexOf(".zip") != -1||$(this).attr("href").indexOf(".xlsx") != -1||$(this).attr("href").indexOf(".docx") != -1||$(this).attr("href").indexOf(".xls") != -1||$(this).attr("href").indexOf(".doc") != -1||$(this).attr("href").indexOf(".pdf") != -1||$(this).attr("href").indexOf(".html") != -1||$(this).attr("href").indexOf(".pptx") != -1||$(this).attr("href").indexOf(".mp4") != -1){
                                            $("body").append("<a href='"+ $(this).attr("href") +"' download  id='downText'>");
                                            document.getElementById("downText").click();
                                            $("#downText").remove();
                                        }else{
                                            Alert1.content = "请先上传文件";
                                            Alert1.init();
                                            Alert1.show();
                                        }
                                    });
                                    // 删除
                                    $(".delBtn").off("click").click(function () {
                                        var $that = $(this);
                                        var text = $(this).attr("data-text");
                                        var json = {"chapterId":chapterId};
                                        if(text == "delCourseware"){
                                            json.delCourseware = true;
                                        }else if(text == "delHomework"){
                                            json.delHomework = true;
                                        }else if(text == "delVideo"){
                                            json.delVideo = true;
                                        }else if(text == "delExprement"){
                                            json.delExprement = true;
                                        }else{
                                            json.delPackageFile = true;
                                        }
                                        json = JSON.stringify(json);
                                        confirm1.contenthead = "提示信息";
                                        confirm1.content = "确定要删除吗？";
                                        confirm1.success = function () {
                                            $.ajax({
                                                type: 'post',
                                                url: 'delChapterFile',
                                                async: true,
                                                data: {
                                                    "jsonStr": json
                                                },
                                                success: function (msg) {
                                                    msg = JSON.parse(msg);
                                                    if (msg.result == "success") {
                                                        that.val("");
                                                        $that.prev().remove();
                                                        $that.remove();
                                                        count = 0;
                                                        $(".downHtml").attr("href","");
                                                        $(".checkBtn").attr("data-src",'');
                                                        $(".checkBtn").siblings("b").attr("data-src",'');
                                                    }else{
                                                        Alert1.content = msg.failMsg;
                                                        Alert1.init();
                                                        Alert1.show();
                                                    }
                                                }
                                            });
                                        };
                                        confirm1.init();
                                        confirm1.show();
                                    });
                                } else {
                                    Alert1.content = msg.failMsg;
                                    that.val("");
                                    Alert1.init();
                                    Alert1.show();
                                }
                            }
                        });
                    }
                }


            });
        },
        editChapterEvent:function (json,type,url,chapterId) {
            var self = this;
            $(".showVideo").attr("src",'');
            $.ajax({
                type: 'post',
                url: 'skipCourseStudyDetailByChpterId',
                async: true,
                data: {
                    "jsonStr": json
                },
                success: function (msg) {
                    msg = JSON.parse(msg);
                    if (msg.result == "success") {
                        var str = '';
                        var address = msg.url;
                        self.address = msg.url;
                        if(type == 1){
                            str = courseWareModel(msg.chapterMsg,url,chapterId);
                        }else if(type == 2){
                            str = courseMaterialModel(msg.chapterMsg.courseMaterialNameHtml!=undefined?unescape(msg.chapterMsg.courseMaterialNameHtml):'',url,chapterId);
                        }else if(type == 3){
                            str = homeworkModel(msg.chapterMsg,msg.stuUrl+msg.chapterMsg.homeworkModelName,chapterId)
                        }else if(type == 4){
                            str = testDocModel(msg.chapterMsg.testNameHtml!=undefined?unescape(msg.chapterMsg.testNameHtml):'',url,chapterId);
                        }else if(type == 5){
                            str = videoModel(msg.chapterMsg,url,chapterId)
                        }else if(type == 6){
                            str = packageFileModel(msg.chapterMsg,url,chapterId)
                        }else{
                            str = reportModel(msg.chapterMsg,url,chapterId)
                        }
                        $(".fileShowSection").append(str);
                        if(type == 7){
                            $('.edit').trumbowyg({
                                lang: 'zh_cn',
                                closable: false,
                                fixedBtnPane: false,
                                fullscreenable: false,
                                btnsDef: {
                                    // Customizables dropdowns
                                    align: {
                                        dropdown: ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
                                        ico: 'justifyLeft'
                                    },
                                    image: {
                                        dropdown: ['insertImage', 'base64'],
                                        ico: 'insertImage'
                                    }
                                },
                                btns: ['formatting',
                                    '|', 'btnGrp-test',
                                    '|', 'align',
                                    '|', 'btnGrp-lists',
                                    '|', 'image',"|"]
                            });
                            $(".edit").html(msg.chapterMsg.expreHtml!=undefined?unescape(msg.chapterMsg.expreHtml):'');
                            // 实验报告保存
                            $(".saveReport").off("click").click(function(){
                                loading1.show();
                                var str = escape($(".edit").html());
                                var json = JSON.stringify({"homeOrExpreMark":2,"chapterId":chapterId,"homewokHtmlStr":"","expreHtmlStr":str,"homworkPaperDetail":"","exprementPaperDetail":200});
                                $.ajax({
                                    type: 'post',
                                    url: 'addHtmlChapter',
                                    async: true,
                                    data: {
                                        "jsonStr": json
                                    },
                                    success: function (msg) {
                                        loading1.hide();
                                        msg = JSON.parse(msg);
                                        if (msg.result != "success") {
                                            Alert1.content = msg.failMsg;
                                            Alert1.init();
                                            Alert1.show();
                                        }else{
                                            Alert1.content = "保存成功";
                                            Alert1.init();
                                            Alert1.show();
                                        }
                                    }
                                });
                            });
                        }
                        if(type == 2 || type == 4){
                            self.testEditor("MarEditormd");
                            $(".enterLab").off("click").click(function () {
                                self.allocateEvent(chapterId);
                            });
                            // 备课材料保存
                            $(".saveMar").off("click").click(function(){
                                var json;
                                if(type == 2){
                                    json = JSON.stringify({"htmlStr":$("#MarEditormd .editormd-preview").html(),"chapterId":chapterId,"testNameHtml":'',"courseMaterialNameHtml":escape($("#MarEditormd textarea").val()),"mark":1});
                                }else{
                                    json = JSON.stringify({"htmlStr":$("#MarEditormd .editormd-preview").html(),"chapterId":chapterId,"testNameHtml":escape($("#MarEditormd textarea").val()),"courseMaterialNameHtml":'',"mark":2});
                                }
                                if($("#MarEditormd textarea").val()!=''&& $("#MarEditormd .markdown-body").html() == ''){
                                    Alert1.content = "请点击预览查看编写效果";
                                    Alert1.init();
                                    Alert1.show();
                                }else{
                                    $.ajax({
                                        type: 'post',
                                        url: 'addChapterMaterialOrTest',
                                        async: true,
                                        data: {
                                            "jsonStr": json
                                        },
                                        success: function (msg) {
                                            msg = JSON.parse(msg);
                                            if (msg.result == "success") {
                                                Alert1.content = "保存成功";
                                                Alert1.init();
                                                Alert1.show();
                                                $(".checkBtn").attr("data-src",address+msg.filename+'?newtime='+ Math.random());
                                                $(".checkBtn").siblings("b").attr("data-src",address+msg.filename+'?newtime='+ Math.random());
                                                $('.checkBtn').click()
                                                // var _iframe1=_body.document.getElementById('showSection');
                                                // _iframe1.contentWindow.location.reload(true);
                                            }else{
                                                if(msg.failMsg!=undefined){
                                                    Alert1.content = msg.failMsg;
                                                }else{
                                                    Alert1.content = "保存失败";
                                                }
                                                Alert1.init();
                                                Alert1.show();
                                            }
                                        }
                                    });
                                }

                            });
                        }
                        var infoStr = $(".tip").html();
                        self.fileEvent(chapterId,infoStr,msg.url,msg.stuUrl);
                        //下载
                        $(".downHtml").off("click").click(function () {
                            if($(this).attr("href").indexOf(".rar") != -1||$(this).attr("href").indexOf(".zip") != -1||$(this).attr("href").indexOf(".xlsx") != -1||$(this).attr("href").indexOf(".docx") != -1||$(this).attr("href").indexOf(".xls") != -1||$(this).attr("href").indexOf(".doc") != -1||$(this).attr("href").indexOf(".pdf") != -1||$(this).attr("href").indexOf(".html") != -1||$(this).attr("href").indexOf(".pptx") != -1||$(this).attr("href").indexOf(".mp4") != -1){
                                $("body").append("<a href='"+ $(this).attr("href") +"' download  id='downText'>");
                                document.getElementById("downText").click();
                                $("#downText").remove();
                            }else{
                                Alert1.content = "请先上传文件";
                                Alert1.init();
                                Alert1.show();
                            }
                        });
                        $(".delBtn").off("click").click(function () {
                            var $that = $(this);
                            var text = $(this).attr("data-text");
                            var json = {"chapterId":chapterId};
                            if(text == "delCourseware"){
                                json.delCourseware = true;
                            }else if(text == "delHomework"){
                                json.delHomework = true;
                            }else if(text == "delVideo"){
                                json.delVideo = true;
                            }else if(text == "delExprement"){
                                json.delExprement = true;
                            }else{
                                json.delPackageFile = true;
                            }
                            json = JSON.stringify(json);
                            confirm1.contenthead = "提示信息";
                            confirm1.content = "确定要删除吗？";
                            confirm1.success = function () {
                                $.ajax({
                                    type: 'post',
                                    url: 'delChapterFile',
                                    async: true,
                                    data: {
                                        "jsonStr": json
                                    },
                                    success: function (msg) {
                                        msg = JSON.parse(msg);
                                        if (msg.result == "success") {
                                            $(".file").val("");
                                            $that.prev().remove();
                                            $that.remove();
                                            count = 0;
                                            $(".downHtml").attr("href","");
                                            $(".checkBtn").attr("data-src",'');
                                            $(".checkBtn").siblings("b").attr("data-src",'');
                                        }else{
                                            Alert1.content = msg.failMsg;
                                            Alert1.init();
                                            Alert1.show();
                                        }
                                    }
                                });
                            };
                            confirm1.init();
                            confirm1.show();
                        });
                    }else{
                        if(msg.failMsg!=undefined){
                            Alert1.content = msg.failMsg;
                        }else{
                            Alert1.content = "获取失败";
                        }
                        Alert1.init();
                        Alert1.show();
                    }
                }
            });
        },
        authority:function(roleId){
//			权限
            if(roleId == 1){
                $(".downloadTea").remove();
                $(".clearProcessBtn").remove();
            }else if(roleId == 2){
                $(".uploadFile").remove();
            }else{
                // $(".download").remove();
                $(".clearProcessBtn").remove();
                $(".uploadFile").remove();
                $(".enterLab").off("click");
                $(".enterLab").removeClass("enterLab");
            }
        },
        btnFun:function(url) {
//			章节中按钮方法
//			查看
            var self = this;

            function videoRemove() {
                //去除video标签
                if ($(".showVideo").length != 0) {
                    $(".showVideo").remove();
                }
            }

//			学习课件
            $(".courseware").off("click").click(function () {
                videoRemove();
                $(".choseBtn").css("background","#fff");
                $(".choseBtn").removeClass("checkBtn");
                $(this).addClass("checkBtn");
                $(".editChapter").hide();
                $(".editSection").remove();
                $(".homeSecBox").remove();
                $(this).siblings("b").show();
                $(this).css("background","#d6eafe");
                if ($(this).attr("data-src").indexOf(".pdf") != -1) {
                    // self.addProcess({"chapterNum":$(this).attr("data-chapternum"),"courseId":$(this).attr("data-courseid")});
                    $showSection.attr("src", "pc/js/extends/generic/web/viewer.html?file=" + $(this).attr("data-src"));
                    $showSection.load(function () {
                        $showSection.contents().find("link").remove();
                        $showSection.contents().find("title").before("<link href='viewer.css' rel='stylesheet'>");
                    });
                } else {
                    $showSection.attr("src", "pc/page/noResourceShow.html");
                }
            });
            //备课材料
            $(".courseMaterial").off("click").click(function () {
                videoRemove();
                $(".choseBtn").css("background","#fff");
                $(".choseBtn").removeClass("checkBtn");
                $(".homeSecBox").remove();
                $(this).addClass("checkBtn");
                $(this).css("background","#d6eafe");
                $(".editSection").remove();
                $(".editChapter").hide();
                $(this).siblings("b").show();
                if ($(this).attr("data-src").indexOf(".html") != -1) {
                    $showSection.attr("src", $(this).attr("data-src"));
                } else {
                    $showSection.attr("src", "pc/page/noResourceShow.html");
                }

            });
            //课后作业
            $(".homework").off("click").click(function () {
                videoRemove();
                $(".choseBtn").css("background","#fff");
                $(".choseBtn").removeClass("checkBtn");
                $(this).addClass("checkBtn");
                $(this).css("background","#d6eafe");
                $(".editSection").remove();
                $(".editChapter").hide();
                $(this).siblings("b").show();
                $(".homeSecBox").remove();
                var json = JSON.stringify({"chapterId":Number($(this).attr("data-chapterid")),"courseId":Number(result.paramData.courseId),"chapterNum":Number($(this).attr("data-chapternum"))});
                $.ajax({
                    type: 'post',
                    url: 'skipCourseStudyDetailByChpterId',
                    async: true,
                    data: {
                        "jsonStr": json
                    },
                    success: function (msg) {
                        msg = JSON.parse(msg);
                        if (msg.result == "success") {
                            if (msg.chapterMsg.taskHtml != '' && msg.chapterMsg.taskHtml != undefined && msg.chapterMsg.taskHtml != null) {
                                var str = homeworkShow(unescape(msg.chapterMsg.taskHtml));
                                $(".fileShowSection").append("<div class='homeSecBox'>"+str+"</div>");
                            } else {
                                $showSection.attr("src", "pc/page/noResourceShow.html");
                            }
                        }else{
                            if(msg.failMsg!=undefined){
                                Alert1.content = msg.failMsg;
                            }else{
                                Alert1.content = "获取失败";
                            }
                            Alert1.init();
                            Alert1.show();
                        }
                    }
                });

            });
            //实验报告
            $(".report").off("click").click(function () {
                videoRemove();
                $(".choseBtn").css("background","#fff");
                $(".choseBtn").removeClass("checkBtn");
                $(this).addClass("checkBtn");
                $(this).css("background","#d6eafe");
                $(".homeSecBox").remove();
                $(".editSection").remove();
                $(".editChapter").hide();
                $(this).siblings("b").show();
                var json = JSON.stringify({"chapterId":Number($(this).attr("data-chapterid")),"courseId":Number(result.paramData.courseId),"chapterNum":Number($(this).attr("data-chapternum"))});
                $.ajax({
                    type: 'post',
                    url: 'skipCourseStudyDetailByChpterId',
                    async: true,
                    data: {
                        "jsonStr": json
                    },
                    success: function (msg) {
                        msg = JSON.parse(msg);
                        if (msg.result == "success") {
                            if (msg.chapterMsg.expreHtml != '' && msg.chapterMsg.expreHtml != undefined && msg.chapterMsg.expreHtml != null) {
                                var str = reportShow(unescape(msg.chapterMsg.expreHtml));
                                $(".fileShowSection").append(str);
                            } else {
                                $showSection.attr("src", "pc/page/noResourceShow.html");
                            }
                        }else{
                            if(msg.failMsg!=undefined){
                                Alert1.content = msg.failMsg;
                            }else{
                                Alert1.content = "获取失败";
                            }
                            Alert1.init();
                            Alert1.show();
                        }
                    }
                });

            });
//			实验手册
            $(".testDoc").off("click").click(function () {
                videoRemove();
                $(".choseBtn").css("background","#fff");
                $(".choseBtn").removeClass("checkBtn");
                $(this).addClass("checkBtn");
                $(".editSection").remove();
                $(this).css("background","#d6eafe");
                $(".homeSecBox").remove();
                $(".editChapter").hide();
                $(this).siblings("b").show();
                // $(this).parent().parent().siblings("a").attr("data-value","1");
                if ($(this).attr("data-src").indexOf(".html") != -1) {
                    $showSection.attr("src", $(this).attr("data-src"));
                } else {
                    $showSection.attr("src", "pc/page/noResourceShow.html");
                }

            });
//			学习视频
            $(".video").off("click").click(function () {
                videoRemove();
                $(".choseBtn").css("background","#fff");
                $(".editSection").remove();
                $(this).css("background","#d6eafe");
                $(".choseBtn").removeClass("checkBtn");
                $(this).addClass("checkBtn");
                $(".homeSecBox").remove();
                $(".editChapter").hide();
                $(this).siblings("b").show();
                $showSection.load(function () {
                    $showSection.contents().find("link").remove();
                });
                $showSection.after("<video autoplay controls class='showVideo'  src='" + $(this).attr("data-src") + "'></video>");
                $('.showVideo').bind('contextmenu', function () {
                    return false;
                });
            });
            //			课程材料
            $(".packageFile").off("click").click(function () {
                videoRemove();
                $(".homeSecBox").remove();
                $(".choseBtn").css("background","#fff");
                $(".choseBtn").removeClass("checkBtn");
                $(this).addClass("checkBtn");
                $(".editSection").remove();
                $(this).css("background","#d6eafe");
                $(".editChapter").hide();
                $(this).siblings("b").show();
                if($(".packageFile").attr("data-src").indexOf(".zip")!=-1){
                    $showSection.attr("src", "pc/page/courseSomeShow.html");
                }else if($(".packageFile").attr("data-src").indexOf(".rar")!=-1){
                    $showSection.attr("src", "pc/page/courseSomeShow.html");
                }else{
                    $showSection.attr("src", "pc/page/noResourceShow.html");
                }
            });
        },
        selectEvent:function(){
            /*导航下拉展开事件*/
            $(".left span").click(function() {
                if($(this).hasClass("up")) {
                    $(this).removeClass("up");
                    $(this).addClass("down");
                    $(this).parent().parent().parent().find("ul").slideToggle(300);
                } else {
                    $(".left ul li ul").slideUp(300);
                    $(".left ul li span").removeClass("up");
                    $(".left ul li span").addClass("down");
                    $(this).removeClass("down");
                    $(this).addClass("up");
                    $(this).parent().parent().parent().find("ul").slideToggle(300);
                }
            });
        }
    };
    myCourse.init();
    //桌面共享
    function startWebSocket(containerId) {
        var path = "";
        $.ajax({
            type:"get",
            url: "common/project",
            async: true,
            success: function(msg) {
                if(msg.code == 200){
                    path = msg.data;
                    // var path = window.location.host+"/";
                    var wsuri = "ws://" + path + "webSocket/image/" + containerId ;
                    if('WebSocket' in window) {
                        ws = new WebSocket(wsuri);
                    } else if('MozWebSocket' in window) {
                        ws = new MozWebSocket(wsuri);
                    } else {
                        Alert1.content = "当前浏览器不支持websocket，不能进行桌面共享";
                        Alert1.init();
                        Alert1.show();
                    }
                    var myDate = new Date();
                    ws.onopen = function() {

                        console.log(myDate.getDate() + ":" + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds() + ":" + myDate.getMilliseconds() + "--onopen");
                    };
                    ws.onmessage = function(evt) {


                    };

                    ws.onclose = function(evt) {
                        console.log(myDate.getDate() + ":" + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds() + ":" + myDate.getMilliseconds() + "--onclose");
                    };
                    ws.onerror = function() {
                        console.log(myDate.getDate() + ":" + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds() + ":" + myDate.getMilliseconds() + "--onerror");
                    };
                }
            }
        });

    }
});